Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2014 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  from numpy import array, asarray, exp, median, inf, log, save, std, sum, zeros 
  27  from minfx.generic import generic_minimise 
  28  from random import gauss 
  29  import re, math 
  30  from tempfile import mkdtemp, NamedTemporaryFile 
  31   
  32   
  33  # relax module imports. 
  34  from auto_analyses import relax_disp 
  35  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  36  from data_store import Relax_data_store; ds = Relax_data_store() 
  37  import dep_check 
  38  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  39  from lib.errors import RelaxError 
  40  from lib.io import extract_data, get_file_path, open_read_file 
  41  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  42  from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop 
  43  from pipe_control.minimise import assemble_scaling_matrix 
  44  from pipe_control.pipes import display 
  45  from specific_analyses.relax_disp.checks import check_missing_r1 
  46  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  47  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  48  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  49  from specific_analyses.relax_disp.model import models_info, nesting_param 
  50  from specific_analyses.relax_disp.parameters import linear_constraints 
  51  from status import Status; status = Status() 
  52  from test_suite.system_tests.base_classes import SystemTestCase 
  53   
  54  # C modules. 
  55  if dep_check.C_module_exp_fn: 
  56      from specific_analyses.relax_fit.optimisation import func_wrapper, dfunc_wrapper, d2func_wrapper 
  57      from target_functions.relax_fit import jacobian, jacobian_chi2, setup 
  58      # Call the python wrapper function to help with list to numpy array conversion. 
  59      func = func_wrapper 
  60      dfunc = dfunc_wrapper 
  61      d2func = d2func_wrapper 
  62   
  63   
64 -class Relax_disp(SystemTestCase):
65 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 66
67 - def __init__(self, methodName='runTest'):
68 """Skip certain tests if the C modules are non-functional. 69 70 @keyword methodName: The name of the test. 71 @type methodName: str 72 """ 73 74 # Execute the base class method. 75 super(Relax_disp, self).__init__(methodName) 76 77 # Tests to skip. 78 blacklist = [ 79 'test_m61b_data_to_m61b' 80 ] 81 if methodName in blacklist: 82 status.skipped_tests.append([methodName, None, self._skip_type]) 83 84 # Missing module. 85 if not dep_check.C_module_exp_fn: 86 # The list of tests to skip. 87 to_skip = [ 88 "test_bug_atul_srivastava", 89 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 90 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 91 "test_estimate_r2eff_err", 92 "test_estimate_r2eff_err_auto", 93 "test_estimate_r2eff_err_methods", 94 "test_finite_value", 95 "test_exp_fit", 96 "test_m61_exp_data_to_m61", 97 "test_r1rho_kjaergaard_auto", 98 "test_r1rho_kjaergaard_auto_check_graphs", 99 "test_r1rho_kjaergaard_man", 100 "test_r1rho_kjaergaard_missing_r1", 101 "test_value_write_calc_rotating_frame_params_auto_analysis" 102 ] 103 104 # Store in the status object. 105 if methodName in to_skip: 106 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 107 108 # If not scipy.optimize.leastsq. 109 if not dep_check.scipy_module: 110 # The list of tests to skip. 111 to_skip = [ 112 "test_estimate_r2eff_err_methods" 113 ] 114 115 # Store in the status object. 116 if methodName in to_skip: 117 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 118 119 # If not NMRPipe showApod program in PATH. 120 if not dep_check.showApod_software: 121 # The list of tests to skip. 122 to_skip = [ 123 "test_show_apod_extract", 124 "test_show_apod_rmsd", 125 "test_show_apod_rmsd_to_file", 126 "test_show_apod_rmsd_dir_to_files" 127 ] 128 129 # Store in the status object. 130 if methodName in to_skip: 131 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 132 133 # If not matplotlib module 134 if not dep_check.matplotlib_module: 135 # The list of tests to skip. 136 to_skip = [ 137 "test_repeat_cpmg" 138 ] 139 140 # Store in the status object. 141 if methodName in to_skip: 142 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
143 144
145 - def setUp(self):
146 """Set up for all the functional tests.""" 147 148 # Create the data pipe. 149 self.interpreter.pipe.create('relax_disp', 'relax_disp') 150 151 # Create a temporary directory for dumping files. 152 ds.tmpdir = mkdtemp() 153 self.tmpdir = ds.tmpdir
154 155
156 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
157 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 158 159 @keyword folder: The name of the folder for the test data. 160 @type folder: str 161 @keyword model_analyse: The name of the model which will be tested. 162 @type model_analyse: str 163 """ 164 165 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 166 167 # Data. 168 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 169 170 ## Experiments 171 # Exp 1 172 sfrq_1 = 500.0*1E6 173 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 174 time_T2_1 = 0.05 175 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 176 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 177 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 178 r2eff_errs_1 = [0.0] * len(ncycs_1) 179 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 180 181 sfrq_2 = 600.0*1E6 182 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 183 time_T2_2 = 0.06 184 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 185 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 186 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 187 r2eff_errs_2 = [0.0] * len(ncycs_2) 188 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 189 190 sfrq_3 = 700.0*1E6 191 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 192 time_T2_3 = 0.07 193 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 194 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 195 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 196 r2eff_errs_3 = [0.0] * len(ncycs_3) 197 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 198 199 # Collect all exps 200 exps = [exp_1, exp_2, exp_3] 201 202 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 203 dw_arr = [1.0, 2.0, 3.0, 4.0] 204 pA_arr = [0.9] 205 kex_arr = [1000.] 206 207 spins = [ 208 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 209 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 210 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 211 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 212 ] 213 214 # Create the data pipe. 215 pipe_name = 'base pipe' 216 pipe_type = 'relax_disp' 217 pipe_bundle = 'relax_disp' 218 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 219 220 # Generate the sequence. 221 for res_name, res_num, spin_name, params in spins: 222 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 223 224 # Set isotope 225 self.interpreter.spin.isotope('15N', spin_id='@N') 226 227 # Now loop over the experiments, to set the variables in relax. 228 exp_ids = [] 229 for exp_i in exps: 230 sfrq, time_T2, ncycs, r2eff_errs = exp_i 231 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 232 exp_ids.append(exp_id) 233 234 ids = [] 235 for ncyc in ncycs: 236 nu_cpmg = ncyc / time_T2 237 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 238 ids.append(cur_id) 239 240 # Set the spectrometer frequency. 241 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 242 243 # Set the experiment type. 244 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 245 246 # Set the relaxation dispersion CPMG constant time delay T (in s). 247 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 248 249 # Set the relaxation dispersion CPMG frequencies. 250 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 251 252 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 253 254 ### Now do fitting. 255 # Change pipe. 256 257 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 258 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 259 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 260 261 # Now read data in. 262 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 263 exp_id = exp_ids[mi] 264 exp_i = exps[mi] 265 sfrq, time_T2, ncycs, r2eff_errs = exp_i 266 267 # Then loop over the spins. 268 for res_name, res_num, spin_name, params in spins: 269 cur_spin_id = ":%i@%s"%(res_num, spin_name) 270 271 # Define file name 272 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 273 274 # Read in the R2eff file to put into spin structure. 275 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 276 277 # Then select model. 278 self.interpreter.relax_disp.select_model(model=model_analyse) 279 280 # Then cluster 281 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 282 283 # Grid search 284 low_arr = R20 + dw_arr + pA_arr + kex_arr 285 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 286 287 # Then loop over the defined spins and read the parameters. 288 for i in range(len(spins)): 289 res_name, res_num, spin_name, params = spins[i] 290 cur_spin_id = ":%i@%s"%(res_num, spin_name) 291 cur_spin = return_spin(cur_spin_id) 292 293 for mo_param in cur_spin.params: 294 print(mo_param) 295 # The R2 is a dictionary, depending on spectrometer frequency. 296 if isinstance(getattr(cur_spin, mo_param), dict): 297 for key, val in getattr(cur_spin, mo_param).items(): 298 should_be = params[mo_param][key] 299 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 300 self.assertAlmostEqual(val, should_be) 301 else: 302 should_be = float(params[mo_param]) 303 val = getattr(cur_spin, mo_param) 304 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 305 self.assertAlmostEqual(val, should_be) 306 307 # Test chi2. 308 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 309 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
310 311
312 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
313 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 314 315 # The path to the data files. 316 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 317 318 # Set pipe name, bundle and type. 319 ds.pipe_name = 'base pipe' 320 ds.pipe_bundle = 'relax_disp' 321 ds.pipe_type = 'relax_disp' 322 323 # Create the data pipe. 324 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 325 326 # Read the spins. 327 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 328 329 # Name the isotope for field strength scaling. 330 self.interpreter.spin.isotope(isotope='15N') 331 332 # Set number of experiments to be used. 333 NR_exp = 70 334 335 # Load the experiments settings file. 336 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 337 expfileslines = expfile.readlines()[:NR_exp] 338 expfile.close() 339 340 # In MHz 341 yOBS = 81.050 342 # In ppm 343 yCAR = 118.078 344 centerPPM_N15 = yCAR 345 346 ## Read the chemical shift data. 347 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 348 349 # The lock power to field, has been found in an calibration experiment. 350 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 351 352 # Apply spectra settings. 353 # Count settings 354 j = 0 355 for i in range(len(expfileslines)): 356 line = expfileslines[i] 357 if line[0] == "#": 358 continue 359 else: 360 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 361 DIRN = line.split()[0] 362 I = int(line.split()[1]) 363 deltadof2 = line.split()[2] 364 dpwr2slock = line.split()[3] 365 ncyc = int(line.split()[4]) 366 trim = float(line.split()[5]) 367 ss = int(line.split()[6]) 368 set_sfrq = float(line.split()[7]) 369 apod_rmsd = float(line.split()[8]) 370 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 371 372 # Calculate spin_lock time 373 time_sl = 2*ncyc*trim 374 375 # Define file name for peak list. 376 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 377 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 378 379 # Load the peak intensities. 380 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 381 382 # Set the peak intensity errors, as defined as the baseplane RMSD. 383 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 384 385 # Set the relaxation dispersion experiment type. 386 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 387 388 # Set The spin-lock field strength, nu1, in Hz 389 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 390 391 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 392 frq_N15_Hz = yOBS * 1E6 393 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 394 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 395 396 # Set The spin-lock offset, omega_rf, in ppm. 397 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 398 399 # Set the relaxation times (in s). 400 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 401 402 # Set the spectrometer frequency. 403 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 404 405 # Add to counter 406 j += 1 407 408 409 print("Testing the number of settings") 410 print("Number of settings iterations is: %s. Number of cdp.exp_type.keys() is: %s"%(i, len(cdp.exp_type.keys() ) ) ) 411 self.assertEqual(70, len(expfileslines)) 412 self.assertEqual(69, j) 413 self.assertEqual(69, len(cdp.exp_type.keys()) ) 414 415 # Cluster spins 416 for curspin in cluster_ids: 417 print("Adding spin %s to cluster"%curspin) 418 self.interpreter.relax_disp.cluster('model_cluster', curspin) 419 420 # De-select for analysis those spins who have not been clustered 421 for free_spin in cdp.clustering['free spins']: 422 print("Deselecting free spin %s"%free_spin) 423 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 424 425 426 #Paper reference values 427 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 428 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 429 ds.ref = dict() 430 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 431 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 432 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 433 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 434 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 435 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 436 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 437 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 438 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 439 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 440 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 441 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 442 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 443 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 444 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 445 446 ds.guess = dict() 447 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 448 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 449 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 450 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 451 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 452 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 453 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 454 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 455 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 456 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 457 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 458 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 459 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 460 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 461 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 462 463 # Assign guess values. 464 for spin, spin_id in spin_loop(return_id=True): 465 if spin_id in cluster_ids: 466 print("spin_id %s in cluster ids"%(spin_id)) 467 spin.kex = ds.guess[spin_id][6] 468 spin.phi_ex = ds.guess[spin_id][10] 469 else: 470 print("spin_id %s NOT in cluster ids"%(spin_id)) 471 472 if read_R1: 473 # Read the R1 data 474 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
475 476
477 - def setup_hansen_cpmg_data(self, model=None):
478 """Set up the data for the test_hansen_cpmg_data_*() system tests. 479 480 @keyword model: The name of the model which will be tested. 481 @type model: str 482 """ 483 484 # Create the data pipe and load the base data. 485 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 486 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 487 self.interpreter.results.read(data_path+sep+'base_pipe') 488 self.interpreter.deselect.spin(':4') 489 490 # Set the nuclear isotope data. 491 self.interpreter.spin.isotope('15N') 492 493 # Create the R2eff data pipe and load the results. 494 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 495 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 496 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 497 self.interpreter.deselect.spin(':4') 498 499 # The model data pipe. 500 pipe_name = "%s - relax_disp" % model 501 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 502 self.interpreter.pipe.switch(pipe_name=pipe_name) 503 504 # Set the model. 505 self.interpreter.relax_disp.select_model(model=model) 506 507 # Copy the data. 508 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
509 510
511 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
512 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 513 514 @keyword model: The name of the model which will be tested. 515 @type model: str 516 """ 517 518 # Create the data pipe and load the base data. 519 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 520 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 521 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 522 523 # Create the R2eff data pipe and load the results. 524 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 525 self.interpreter.pipe.switch(pipe_name='R2eff') 526 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 527 528 # The model data pipe. 529 pipe_name = "%s - relax_disp" % model 530 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 531 self.interpreter.pipe.switch(pipe_name=pipe_name) 532 533 # Set the model. 534 self.interpreter.relax_disp.select_model(model=model) 535 536 # Copy the data. 537 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
538 539
540 - def setup_korzhnev_2005_data(self, data_list=[]):
541 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 542 543 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 544 545 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 546 547 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 548 549 550 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 551 @type data_list: list of str 552 """ 553 554 # Create the data pipe and load the base data. 555 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 556 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 557 558 # Create the spin system. 559 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 560 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 561 self.interpreter.spin.element('H', spin_id='@H') 562 self.interpreter.spin.element('N', spin_id='@N') 563 self.interpreter.spin.isotope('1H', spin_id='@H') 564 self.interpreter.spin.isotope('15N', spin_id='@N') 565 566 # Define the magnetic dipole-dipole relaxation interaction. 567 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 568 569 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 570 data = [ 571 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 572 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 573 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 574 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 575 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 576 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 577 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 578 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 579 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 580 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 581 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 582 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 583 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 584 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 585 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 586 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 587 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 588 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 589 ] 590 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 591 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 592 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 593 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 594 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 595 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 596 597 # Loop over the files, reading in the data. 598 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 599 # Skip undesired data. 600 if data_type not in data_list: 601 continue 602 603 # Alias the CPMG frequencies. 604 if data_type == 'SQ': 605 cpmg_frqs = cpmg_frqs_sq 606 elif data_type == '1H SQ': 607 cpmg_frqs = cpmg_frqs_1h_sq 608 elif data_type == 'DQ': 609 cpmg_frqs = cpmg_frqs_dq 610 elif data_type == 'ZQ': 611 cpmg_frqs = cpmg_frqs_zq 612 elif data_type == '1H MQ': 613 cpmg_frqs = cpmg_frqs_1h_mq 614 elif data_type == 'MQ': 615 cpmg_frqs = cpmg_frqs_mq 616 617 # Loop over each CPMG frequency. 618 for cpmg_frq in cpmg_frqs: 619 # The id. 620 new_id = "%s_%s" % (id, cpmg_frq) 621 622 # Set the NMR field strength. 623 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 624 625 # Set the relaxation dispersion experiment type. 626 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 627 628 # Relaxation dispersion CPMG constant time delay T (in s). 629 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 630 631 # Set the CPMG frequency. 632 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 633 634 # Read the R2eff data. 635 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 636 637 # Change the model. 638 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
639 640
641 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
642 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 643 644 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 645 'SOD1-WT' CPMG data to the CR72 dispersion model. 646 647 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 648 Data is for experiment at 25 degree Celcius. 649 """ 650 651 # Create the data pipe and load the base data. 652 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 653 654 # Set experiment settings. sfrq, time_T2, ncyc 655 Exps = [ 656 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 657 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 658 659 # Create base pipe 660 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 661 662 # Loop throug experiments 663 id_lists = [] 664 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 665 # Read spins 666 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 667 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 668 669 # Make spectrum id list 670 id_list = list(key+str(i) for i in range(len(ncycs))) 671 id_lists.append(id_list) 672 673 # Read intensities 674 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 675 676 # Loop over experiments 677 for i in range(len(ncycs)): 678 ncyc = ncycs[i] 679 vcpmg = ncyc/time_T2 680 681 # Test if spectrum is a reference 682 if float(vcpmg) == 0.0: 683 vcpmg = None 684 else: 685 vcpmg = round(float(vcpmg), 3) 686 687 # Set current id 688 current_id = id_list[i] 689 690 # Set the current experiment type. 691 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 692 693 # Set the NMR field strength of the spectrum. 694 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 695 696 # Relaxation dispersion CPMG constant time delay T (in s). 697 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 698 699 # Set the relaxation dispersion CPMG frequencies. 700 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 701 702 # Define replicated 703 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 704 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 705 706 # Perform error analysis 707 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 708 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 709 710 # Define isotope 711 self.interpreter.spin.isotope(isotope='15N') 712 713 ############# 714 715 # Define the 64 residues which was used for Global fitting 716 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 717 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 718 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 719 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 720 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 721 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 722 723 # Test number of global 724 self.assertEqual(64, len(glob_assn )) 725 726 ## Turn assignments into relax spin ids. 727 # Define regular expression search 728 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 729 730 # Create list to hold regular expression search 731 relax_glob_ids = [] 732 733 # Loop over assignments 734 for assn in glob_assn: 735 # Make match for the regular search 736 m = r.match(assn) 737 # Convert to relax spin string 738 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 739 740 # Save the relax spin string and the regular search 741 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 742 743 ############# Deselect all spins, and select few spins 744 745 ## Deselect all spins, and select a few for analysis 746 self.interpreter.deselect.all() 747 748 # Select few spins 749 for i in select_spin_index: 750 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 751 752 ############## 753 754 # Prepare for R2eff calculation 755 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 756 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 757 758 # Select model for points calculation 759 MODEL = "R2eff" 760 self.interpreter.relax_disp.select_model(model=MODEL) 761 # Calculate R2eff values 762 self.interpreter.minimise.calculate(verbosity=1)
763 764
765 - def setup_missing_r1_spins(self):
766 """Function for setting up a few spins for the given pipe.""" 767 768 # Path to file. 769 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 770 771 # File with spins. 772 file = open(data_path+sep+'R1_fitted_values.txt') 773 lines = file.readlines() 774 file.close() 775 776 for i, line in enumerate(lines): 777 # Make the string test 778 line_split = line.split() 779 780 if line_split[0] == "#": 781 continue 782 783 mol_name = line_split[0] 784 mol_name = None 785 res_num = int(line_split[1]) 786 res_name = line_split[2] 787 spin_num = line_split[3] 788 spin_num = None 789 spin_name = line_split[4] 790 791 # Create the spin. 792 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
793 794
795 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
796 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 797 798 # Reset. 799 self.interpreter.reset() 800 801 # Create the data pipe and load the base data. 802 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 803 self.interpreter.state.load(data_path+sep+'r2eff_values') 804 805 # The model data pipe. 806 model = 'NS R1rho 2-site' 807 pipe_name = "%s - relax_disp" % model 808 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 809 self.interpreter.pipe.switch(pipe_name=pipe_name) 810 811 # Set the model. 812 self.interpreter.relax_disp.select_model(model=model) 813 814 # Copy the data. 815 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 816 817 # Alias the spins. 818 spin1 = cdp.mol[0].res[0].spin[0] 819 spin2 = cdp.mol[0].res[1].spin[0] 820 821 # The R20 keys. 822 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 823 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 824 825 # Set the initial parameter values. 826 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 827 spin1.pA = 0.779782428085762 828 spin1.dw = 7.57855284496424 829 spin1.kex = 1116.7911285203 830 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 831 spin2.pA = 0.826666229688602 832 spin2.dw = 9.5732624231366 833 spin2.kex = 1380.46162655657 834 835 # Test the values when clustering. 836 if clustering: 837 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 838 839 # Low precision optimisation. 840 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 841 842 # Printout. 843 print("\n\nOptimised parameters:\n") 844 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 845 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 846 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 847 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 848 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 849 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 850 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
851 852
853 - def test_baldwin_synthetic(self):
854 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 855 856 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 857 858 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 859 """ 860 861 # The path to the data files. 862 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 863 864 # Create pipe 865 pipe_name = 'base pipe' 866 pipe_type = 'relax_disp' 867 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 868 869 # Create base pipe 870 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 871 872 # Generate the sequence. 873 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 874 875 # Define the isotope. 876 self.interpreter.spin.isotope('1H', spin_id='@H') 877 878 # Build the experiment IDs. 879 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 880 ncycs = [2, 4, 8, 10, 20, 40, 500] 881 ids = [] 882 for ncyc in ncycs: 883 ids.append('CPMG_%s' % ncyc) 884 885 print("\n\nThe experiment IDs are %s." % ids) 886 887 # Set up the metadata for the experiments. 888 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 889 sfrq = 200. * 1E6 890 891 # Total time of CPMG block. 892 Trelax = 0.04 893 894 # First set the 895 for i in range(len(ids)): 896 id = ids[i] 897 # Set the spectrometer frequency. 898 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 899 900 # Set the experiment type. 901 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 902 903 # Set the relaxation dispersion CPMG constant time delay T (in s). 904 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 905 906 # Set the relaxation dispersion CPMG frequencies. 907 ncyc = ncycs[i] 908 nu_cpmg = ncyc / Trelax 909 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 910 911 # Prepare for R2eff reading. 912 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 913 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 914 915 # Try reading the R2eff file. 916 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 917 918 # Check the global data. 919 data = [ 920 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 921 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 922 ['dispersion_points', len(ncycs)], 923 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 924 ['exp_type_list', ['SQ CPMG']], 925 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 926 ['spectrometer_frq_count', 1], 927 ['spectrometer_frq_list', [sfrq]], 928 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 929 ] 930 for name, value in data: 931 # Does it exist? 932 self.assert_(hasattr(cdp, name)) 933 934 # Check the object. 935 obj = getattr(cdp, name) 936 if not isinstance(data, dict): 937 self.assertEqual(obj, value) 938 939 # Check the global dictionary data. 940 else: 941 for id in ids: 942 self.assertEqual(obj[id], value[id]) 943 944 # Check the spin data. 945 n_data = [ 946 [ 50.000000, 10.367900, 0.1], 947 [ 100.000000, 10.146849, 0.1], 948 [ 200.000000, 9.765987, 0.1], 949 [ 250.000000, 9.409789, 0.1], 950 [ 500.000000, 5.829819, 0.1], 951 [ 1000.000000, 3.191928, 0.1], 952 [ 12500.000000, 2.008231, 0.1] 953 ] 954 for disp_point, value, error in n_data: 955 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 956 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 957 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 958 959 # Generate r20 key. 960 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 961 962 ## Now prepare for MODEL calculation. 963 MODEL = "B14" 964 965 # Change pipe. 966 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 967 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 968 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 969 970 # Then select model. 971 self.interpreter.relax_disp.select_model(model=MODEL) 972 973 # Store grid and minimisations results. 974 grid_results = [] 975 mini_results = [] 976 977 # The grid search size (the number of increments per dimension). 978 # If None, use the default values. 979 #GRID = None 980 GRID = 13 981 # Perform Grid Search. 982 if GRID: 983 # Set the R20 parameters in the default grid search using the minimum R2eff value. 984 # This speeds it up considerably. 985 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 986 987 # Then do grid search. 988 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 989 990 # If no Grid search, set the default values. 991 else: 992 for param in MODEL_PARAMS[MODEL]: 993 self.interpreter.value.set(param=param, index=None) 994 # Do a grid search, which will store the chi2 value. 995 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 996 997 # Store result. 998 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 999 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1000 1001 ## Now do minimisation. 1002 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1003 set_func_tol = 1e-10 1004 set_max_iter = 1000 1005 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1006 1007 # Store result. 1008 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1009 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1010 1011 # Print results. 1012 for i in range(len(grid_results)): 1013 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1014 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1015 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1016 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1017 1018 # Reference values from Baldwin.py. 1019 # Exchange rate = k+ + k- (s-1) 1020 kex = 1000. 1021 # Fractional population of excited state k+/kex 1022 pb = 0.01 1023 # deltaOmega in ppm 1024 dw_ppm = 2. 1025 #relaxation rate of ground (s-1) 1026 R2g = 2. 1027 #relaxation rate of excited (s-1) 1028 R2e = 2. 1029 1030 # Test the parameters which created the data. 1031 # This is for the 1H spin. 1032 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1033 1034 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1035 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1036 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1037 1038
1040 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1041 1042 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1043 """ 1044 1045 # The path to the data files. 1046 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1047 1048 # Create pipe 1049 pipe_name = 'base pipe' 1050 pipe_type = 'relax_disp' 1051 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1052 1053 # Create base pipe 1054 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1055 1056 # Generate the sequence. 1057 # Generate both a 1H spin, and 15N spin. 1058 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1059 1060 # Define the isotope. 1061 self.interpreter.spin.isotope('1H', spin_id='@H') 1062 1063 # Build the experiment IDs. 1064 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1065 ncycs = [2, 4, 8, 10, 20, 40, 500] 1066 ids = [] 1067 for ncyc in ncycs: 1068 ids.append('CPMG_%s' % ncyc) 1069 1070 print("\n\nThe experiment IDs are %s." % ids) 1071 1072 # Set up the metadata for the experiments. 1073 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1074 sfrq = 200. * 1E6 1075 1076 # Total time of CPMG block. 1077 Trelax = 0.04 1078 1079 # First set the 1080 for i in range(len(ids)): 1081 id = ids[i] 1082 # Set the spectrometer frequency. 1083 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1084 1085 # Set the experiment type. 1086 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1087 1088 # Set the relaxation dispersion CPMG constant time delay T (in s). 1089 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1090 1091 # Set the relaxation dispersion CPMG frequencies. 1092 ncyc = ncycs[i] 1093 nu_cpmg = ncyc / Trelax 1094 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1095 1096 # Prepare for R2eff reading. 1097 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1098 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1099 1100 # Try reading the R2eff file. 1101 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1102 1103 # Check the global data. 1104 data = [ 1105 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1106 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1107 ['dispersion_points', len(ncycs)], 1108 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1109 ['exp_type_list', ['SQ CPMG']], 1110 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1111 ['spectrometer_frq_count', 1], 1112 ['spectrometer_frq_list', [sfrq]], 1113 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1114 ] 1115 for name, value in data: 1116 # Does it exist? 1117 self.assert_(hasattr(cdp, name)) 1118 1119 # Check the object. 1120 obj = getattr(cdp, name) 1121 if not isinstance(data, dict): 1122 self.assertEqual(obj, value) 1123 1124 # Check the global dictionary data. 1125 else: 1126 for id in ids: 1127 self.assertEqual(obj[id], value[id]) 1128 1129 # Check the spin data. 1130 n_data = [ 1131 [ 50.000000, 10.286255, 0.1], 1132 [ 100.000000, 10.073083, 0.1], 1133 [ 200.000000, 9.692746, 0.1], 1134 [ 250.000000, 9.382441, 0.1], 1135 [ 500.000000, 6.312396, 0.1], 1136 [ 1000.000000, 3.957029, 0.1], 1137 [ 12500.000000, 2.880420, 0.1] 1138 ] 1139 for disp_point, value, error in n_data: 1140 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1141 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1142 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1143 1144 # Generate r20 key. 1145 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1146 1147 ## Now prepare for MODEL calculation. 1148 MODEL = "B14 full" 1149 1150 # Change pipe. 1151 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1152 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1153 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1154 1155 # Then select model. 1156 self.interpreter.relax_disp.select_model(model=MODEL) 1157 1158 # Store grid and minimisations results. 1159 grid_results = [] 1160 mini_results = [] 1161 clust_results = [] 1162 1163 # The grid search size (the number of increments per dimension). 1164 # If None, use the default values. 1165 #GRID = None 1166 GRID = 13 1167 # Perform Grid Search. 1168 if GRID: 1169 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1170 # This speeds it up considerably. 1171 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1172 1173 # Then do grid search. 1174 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1175 1176 # If no Grid search, set the default values. 1177 else: 1178 for param in MODEL_PARAMS[MODEL]: 1179 self.interpreter.value.set(param=param, index=None) 1180 # Do a grid search, which will store the chi2 value. 1181 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1182 1183 # Store result. 1184 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1185 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1186 1187 ## Now do minimisation. 1188 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1189 set_func_tol = 1e-11 1190 set_max_iter = 10000 1191 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1192 1193 # Store result. 1194 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1195 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1196 1197 print("\n# Now print before and after minimisation-\n") 1198 1199 # Print results. 1200 for i in range(len(grid_results)): 1201 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1202 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1203 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1204 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1205 1206 # Reference values from Baldwin.py. 1207 # Exchange rate = k+ + k- (s-1) 1208 kex = 1000. 1209 # Fractional population of excited state k+/kex 1210 pb = 0.01 1211 # deltaOmega in ppm 1212 dw_ppm = 2. 1213 #relaxation rate of ground (s-1) 1214 R2g = 2. 1215 #relaxation rate of excited (s-1) 1216 R2e = 100. 1217 1218 # Test the parameters which created the data. 1219 # This is for the 1H spin. 1220 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 4) 1221 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key], R2e, 2) 1222 1223 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1224 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1225 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 2)
1226 1227
1228 - def x_test_bmrb_sub_cpmg(self):
1229 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1230 This uses CPMG data from: 1231 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1232 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1233 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1234 """ 1235 1236 # Define path to data 1237 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1238 1239 # Read data. 1240 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1241 1242 # Set element 1243 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1244 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1245 # Rename molecule from None to 'HEWL' 1246 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1247 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1248 1249 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1250 print(spin_id) 1251 if resn == 'C': 1252 print(resi, resn) 1253 1254 # Select the thiol state of the system. 1255 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1256 self.interpreter.bmrb.thiol_state(state='not reported') 1257 1258 # relax_data.temp_calibration(ri_id=None, method=None) 1259 1260 # Call display of bmrb. 1261 self.interpreter.bmrb.display()
1262 1263
1265 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1266 1267 # Clear the data store. 1268 self.interpreter.reset() 1269 1270 # Load the state. 1271 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1272 self.interpreter.state.load(state, force=True) 1273 1274 # Model selection - to catch the failure. 1275 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1276 1277
1279 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1280 1281 # Clear the data store. 1282 self.interpreter.reset() 1283 1284 # Load the state. 1285 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1286 self.interpreter.state.load(state, force=True) 1287 1288 # Execute the auto-analysis (fast). 1289 relax_disp.Relax_disp.opt_func_tol = 1e-5 1290 relax_disp.Relax_disp.opt_max_iterations = 1000 1291 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1292 1293
1295 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1296 1297 # Clear the data store. 1298 self.interpreter.reset() 1299 1300 # Load the state. 1301 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1302 self.interpreter.state.load(state, force=True) 1303 1304 # Execute the auto-analysis (fast). 1305 relax_disp.Relax_disp.opt_func_tol = 1e-5 1306 relax_disp.Relax_disp.opt_max_iterations = 1000 1307 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1308 1309
1311 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1312 1313 # Clear the data store. 1314 self.interpreter.reset() 1315 1316 # Load the state. 1317 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1318 self.interpreter.state.load(state, force=True) 1319 1320 # Run the calculation. 1321 self.interpreter.minimise.calculate(verbosity=1)
1322 1323
1325 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1326 1327 # Clear the data store. 1328 self.interpreter.reset() 1329 1330 # Load the state. 1331 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1332 self.interpreter.state.load(state, force=True) 1333 1334 # Execute the auto-analysis (fast). 1335 relax_disp.Relax_disp.opt_func_tol = 1e-5 1336 relax_disp.Relax_disp.opt_max_iterations = 1000 1337 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1338 1339
1341 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1342 1343 # Clear the data store. 1344 self.interpreter.reset() 1345 1346 # Load the state. 1347 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1348 self.interpreter.state.load(state, force=True) 1349 1350 # Execute the auto-analysis (fast). 1351 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1352 relax_disp.Relax_disp.opt_func_tol = 1e-5 1353 relax_disp.Relax_disp.opt_max_iterations = 1000 1354 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=2, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1355 1356
1358 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1359 1360 # Base data setup. 1361 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1362 1363
1365 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1366 1367 # Base data setup. 1368 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1369 1370
1372 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1373 1374 # Base data setup. 1375 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1376 1377
1379 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1380 1381 # Base data setup. 1382 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1383 1384
1386 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1387 1388 # Clear the data store. 1389 self.interpreter.reset() 1390 1391 # Load the state. 1392 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1393 self.interpreter.state.load(state, force=True) 1394 1395 param = 'k_AB' 1396 1397 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1398 print(spin_id, spin.params) 1399 if param in spin.params: 1400 print(spin_id, spin.k_AB, spin.k_AB_err) 1401 1402 # Perform write. 1403 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1404 1405 1406 # Test the header of the value.write parameter r2. 1407 param = 'r2' 1408 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1409 1410 file = open(self.tmpdir+sep+'%s.out'%param) 1411 lines = file.readlines() 1412 file.close() 1413 1414 for i, line in enumerate(lines): 1415 # Make the string test 1416 line_split = line.split() 1417 print(line_split) 1418 1419 if len(line_split) > 1: 1420 # Break at parameter header. 1421 if line_split[0] == "#" and line_split[1] == 'mol_name': 1422 nr_split_header = len(line_split) 1423 nr_split_header_i = i 1424 break 1425 1426 # Call the line after. 1427 line_split_val = lines[nr_split_header_i + 1].split() 1428 print(line_split_val) 1429 1430 # Assert that the number of columns is equal, plus 1 for "#". 1431 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1432 1433 # Test the header of the value.write for parameter r2eff. 1434 param = 'r2eff' 1435 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1436 1437 file = open(self.tmpdir+sep+'%s.out'%param) 1438 lines = file.readlines() 1439 file.close() 1440 1441 for i, line in enumerate(lines): 1442 # Make the string test 1443 line_split = line.split() 1444 print(line_split) 1445 1446 if len(line_split) > 1: 1447 # Break at parameter header. 1448 if line_split[0] == "#" and line_split[1] == 'mol_name': 1449 nr_split_header = len(line_split) 1450 nr_split_header_i = i 1451 break 1452 1453 # Call the line after. 1454 line_split_val = lines[nr_split_header_i + 1].split() 1455 print(line_split_val) 1456 1457 # Assert that the number of columns is equal, plus 1 for "#". 1458 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1459 1460
1462 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1463 1464 # Define path to data 1465 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1466 1467 # Read data. 1468 self.interpreter.results.read(prev_data_path + sep + 'results') 1469 1470 # Now count number 1471 graph_nr = 1 1472 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1473 print("\nGraph nr %i" % graph_nr) 1474 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1475 print(exp_type, frq, offset, point, time) 1476 graph_nr += 1 1477 1478 ## Possibly do an error analysis. 1479 1480 # Check if intensity errors have already been calculated by the user. 1481 precalc = True 1482 for spin in spin_loop(skip_desel=True): 1483 # No structure. 1484 if not hasattr(spin, 'peak_intensity_err'): 1485 precalc = False 1486 break 1487 1488 # Determine if a spectrum ID is missing from the list. 1489 for id in cdp.spectrum_ids: 1490 if id not in spin.peak_intensity_err: 1491 precalc = False 1492 break 1493 1494 # Skip. 1495 if precalc: 1496 print("Skipping the error analysis as it has already been performed.") 1497 1498 else: 1499 # Loop over the spectrometer frequencies. 1500 for frq in loop_frq(): 1501 # Generate a list of spectrum IDs matching the frequency. 1502 ids = [] 1503 for id in cdp.spectrum_ids: 1504 # Check that the spectrometer frequency matches. 1505 match_frq = True 1506 if frq != None and cdp.spectrometer_frq[id] != frq: 1507 match_frq = False 1508 1509 # Add the ID. 1510 if match_frq: 1511 ids.append(id) 1512 1513 # Run the error analysis on the subset. 1514 self.interpreter.spectrum.error_analysis(subset=ids) 1515 1516 print("has_exponential_exp_type:", has_exponential_exp_type()) 1517 1518 model = 'R2eff' 1519 self.interpreter.relax_disp.select_model(model) 1520 1521 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1522 #delattr(spin, 'r2eff') 1523 #delattr(spin, 'r2eff_err') 1524 #delattr(spin, 'i0') 1525 #delattr(spin, 'i0_err') 1526 setattr(spin, 'r2eff', {}) 1527 setattr(spin, 'r2eff_err', {}) 1528 setattr(spin, 'i0', {}) 1529 setattr(spin, 'i0_err', {}) 1530 1531 # Do Grid Search 1532 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1533 1534 # Start dic. 1535 my_dic = {} 1536 1537 # Define counter for maximum elements in the numpy array list 1538 NE = 0 1539 NS = 1 1540 NM = 0 1541 NO = 0 1542 ND = 0 1543 NT = 0 1544 1545 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1546 # Save to counter. 1547 if ei > NE: 1548 NE = ei 1549 if mi > NM: 1550 NM = mi 1551 if oi > NO: 1552 NO = oi 1553 if di > ND: 1554 ND = di 1555 1556 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1557 # Save to counter. 1558 if ti > NT: 1559 NT = ti 1560 1561 # Add 1 to counter, since index start from 0. 1562 NE = NE + 1 1563 NM = NM + 1 1564 NO = NO + 1 1565 ND = ND + 1 1566 NT = NT + 1 1567 1568 # Make data array. 1569 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1570 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1571 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1572 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1573 param_key_list = [] 1574 1575 1576 # Loop over each spectrometer frequency and dispersion point. 1577 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1578 # Add key to dic. 1579 my_dic[spin_id] = {} 1580 1581 # Generate spin string. 1582 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1583 1584 # Loop over the parameters. 1585 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1586 1587 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1588 # Generate the param_key. 1589 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1590 1591 # Append key. 1592 param_key_list.append(param_key) 1593 1594 # Add key to dic. 1595 my_dic[spin_id][param_key] = {} 1596 1597 # Get the value. 1598 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1599 i0_value = getattr(cur_spin, 'i0')[param_key] 1600 1601 # Save to dic. 1602 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1603 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1604 1605 ## Now try do a line of best fit by least squares. 1606 # The peak intensities, errors and times. 1607 values = [] 1608 errors = [] 1609 times = [] 1610 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1611 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1612 values.append(value) 1613 1614 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1615 errors.append(error) 1616 times.append(time) 1617 1618 # Save to numpy arrays. 1619 values_arr[ei, 0, mi, oi, di, ti] = value 1620 errors_arr[ei, 0, mi, oi, di, ti] = error 1621 times_arr[ei, 0, mi, oi, di, ti] = time 1622 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1623 1624 # y= A exp(x * k) 1625 # w[i] = ln(y[i]) 1626 # int[i] = i0 * exp( - times[i] * r2eff); 1627 w = log(array(values)) 1628 x = - array(times) 1629 n = len(times) 1630 1631 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1632 a = 1./n * sum(w) - b * 1./n * sum(x) 1633 R2eff_est = b 1634 i0_est = exp(a) 1635 1636 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1637 my_dic[spin_id][param_key]['i0_est'] = i0_est 1638 1639 # Print value. 1640 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1641 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1642 1643 1644 # Do minimisation. 1645 set_func_tol = 1e-25 1646 set_max_iter = int(1e7) 1647 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1648 1649 # Loop over each spectrometer frequency and dispersion point. 1650 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1651 # Generate spin string. 1652 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1653 1654 # Loop over the parameters. 1655 print("Optimised parameters for spin: %s" % (spin_string)) 1656 1657 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1658 # Generate the param_key. 1659 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1660 1661 # Get the value. 1662 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1663 i0_value = getattr(cur_spin, 'i0')[param_key] 1664 1665 # Extract from dic. 1666 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1667 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1668 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1669 i0_est = my_dic[spin_id][param_key]['i0_est'] 1670 1671 # Print value. 1672 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1673 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1674 1675 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1676 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1677 1678 print(NE, NS, NM, NO, ND, NT) 1679 for param_key in param_key_list: 1680 print(" '%s'," % param_key) 1681 print(values_arr.shape) 1682 1683 # Save arrays to profiling. 1684 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1685 #save(data_path + "values_arr", values_arr) 1686 #save(data_path + "errors_arr", errors_arr) 1687 #save(data_path + "times_arr", times_arr) 1688 #save(data_path + "struct_arr", struct_arr) 1689 1690
1691 - def test_bug_atul_srivastava(self):
1692 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1693 shows it is exponential fitting, but only one time point is added per file. 1694 1695 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1696 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1697 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1698 1699 """ 1700 1701 # Data path. 1702 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1703 file = data_path + sep + 'bug_script.py' 1704 1705 # Run script. 1706 self.interpreter.script(file=file, dir=None) 1707 1708 # The grid search size (the number of increments per dimension). 1709 GRID_INC = 11 1710 1711 # Check-data. 1712 ################# 1713 1714 # Loop over spins, to see current setup. 1715 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1716 print(mol_name, resi, resn, spin_id) 1717 1718 # Loop over setup. 1719 for id in cdp.exp_type.keys(): 1720 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1721 1722 1723 # Manual minimisation. 1724 ################# 1725 if True: 1726 # Set the model. 1727 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1728 1729 # Check if intensity errors have already been calculated. 1730 check_intensity_errors() 1731 1732 # Calculate the R2eff values for the fixed relaxation time period data types. 1733 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1734 self.interpreter.minimise.calculate() 1735 1736 # Optimise the model. 1737 else: 1738 constraints = False 1739 min_algor = 'Newton' 1740 with self.assertRaises(RelaxError): 1741 self.interpreter.minimise.grid_search(inc=GRID_INC) 1742 1743 with self.assertRaises(RelaxError): 1744 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 1745 # Inspect. 1746 if False: 1747 # Loop over attributes. 1748 par_attr_list = ['r2eff', 'i0'] 1749 1750 # Collect the estimation data. 1751 my_dic = {} 1752 param_key_list = [] 1753 est_keys = [] 1754 est_key = 'grid' 1755 est_keys.append(est_key) 1756 spin_id_list = [] 1757 1758 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1759 # Add key to dic. 1760 my_dic[spin_id] = {} 1761 1762 # Add key for estimate. 1763 my_dic[spin_id][est_key] = {} 1764 1765 # Add spin key to list. 1766 spin_id_list.append(spin_id) 1767 1768 # Generate spin string. 1769 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1770 1771 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1772 # Generate the param_key. 1773 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1774 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1775 1776 # Append key. 1777 param_key_list.append(param_key) 1778 1779 # Add key to dic. 1780 my_dic[spin_id][est_key][param_key] = {} 1781 1782 # Get the value. 1783 # Loop over err attributes. 1784 for par_attr in par_attr_list: 1785 if hasattr(cur_spin, par_attr): 1786 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1787 else: 1788 get_par_attr = 0.0 1789 1790 # Save to dic. 1791 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1792 1793 # Check number of values. 1794 values = [] 1795 errors = [] 1796 times = [] 1797 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1798 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1799 values.append(value) 1800 1801 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1802 errors.append(error) 1803 times.append(time) 1804 1805 # Save to dic. 1806 my_dic[spin_id][est_key][param_key]['values'] = values 1807 my_dic[spin_id][est_key][param_key]['errors'] = errors 1808 my_dic[spin_id][est_key][param_key]['times'] = times 1809 1810 # Analysis variables. 1811 ##################### 1812 1813 # The dispersion models. 1814 MODELS = ['R2eff', 'No Rex'] 1815 1816 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1817 MC_NUM = 10 1818 1819 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1820 MC_SIM_ALL_MODELS = False 1821 1822 # The results directory. 1823 RESULTS_DIR = ds.tmpdir 1824 1825 # The directory of results of an earlier analysis without clustering. 1826 PRE_RUN_DIR = None 1827 1828 # The model selection technique to use. 1829 MODSEL = 'AIC' 1830 1831 # The flag for only using numeric models in the final model selection. 1832 NUMERIC_ONLY = False 1833 1834 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1835 INSIGNIFICANCE = 1.0 1836 1837 # Auto-analysis execution. 1838 with self.assertRaises(RelaxError): 1839 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1840 1841
1843 """Test data, where peak intensities are negative in CPMG 1844 1845 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1846 """ 1847 1848 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1849 1850 # Create the spins 1851 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1852 1853 # Name the isotope for field strength scaling. 1854 self.interpreter.spin.isotope(isotope='15N') 1855 1856 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1857 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1858 1859 # Loop over the spectra settings. 1860 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1861 1862 # Make empty ncyclist 1863 ncyclist = [] 1864 1865 i = 0 1866 for line in ncycfile: 1867 ncyc = line.split()[0] 1868 time_T2 = float(line.split()[1]) 1869 vcpmg = line.split()[2] 1870 set_sfrq = float(line.split()[3]) 1871 rmsd_err = float(line.split()[4]) 1872 1873 # Test if spectrum is a reference 1874 if float(vcpmg) == 0.0: 1875 vcpmg = None 1876 else: 1877 vcpmg = round(float(vcpmg), 3) 1878 1879 # Add ncyc to list 1880 ncyclist.append(int(ncyc)) 1881 1882 # Set the current spectrum id 1883 current_id = "Z_A%s"%(i) 1884 1885 # Set the current experiment type. 1886 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1887 1888 # Set the peak intensity errors, as defined as the baseplane RMSD. 1889 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1890 1891 # Set the NMR field strength of the spectrum. 1892 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1893 1894 # Relaxation dispersion CPMG constant time delay T (in s). 1895 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1896 1897 # Set the relaxation dispersion CPMG frequencies. 1898 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1899 1900 i += 1 1901 1902 # Specify the duplicated spectra. 1903 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 1904 1905 # Delete replicate spectrum 1906 #self.interpreter.spectrum.delete('Z_A15') 1907 1908 MODELS = [MODEL_R2EFF, MODEL_NOREX] 1909 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 1910 1911 results_dir = ds.tmpdir 1912 1913 # Execute 1914 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 1915 1916 # Check spin less R2eff points. 1917 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 1918 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 1919 if spin_id == ':4@N': 1920 self.assertEqual(len(cur_spin.r2eff), 14) 1921 else: 1922 self.assertEqual(len(cur_spin.r2eff), 15)
1923 1924
1925 - def test_check_missing_r1(self):
1926 """Test of the check_missing_r1() function.""" 1927 1928 # Set up some spins. 1929 self.setup_missing_r1_spins() 1930 1931 # Set variables. 1932 exp_type = 'R1rho' 1933 frq = 800.1 * 1E6 1934 1935 spectrum_id='test' 1936 1937 # Set an experiment type to the pipe. 1938 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 1939 1940 # Set a frequency to loop through. 1941 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 1942 1943 # Check R1 for DPL94. 1944 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1945 self.assertEqual(check_missing_r1_return, True) 1946 1947 # Check R1 for R2eff. 1948 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 1949 self.assertEqual(check_missing_r1_return, False) 1950 1951 # The path to the data files. 1952 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 1953 1954 # Now load some R1 data. 1955 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 1956 1957 # Check R1. 1958 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1959 self.assertEqual(check_missing_r1_return, False)
1960 1961
1963 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 1964 1965 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 1966 1967 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 1968 """ 1969 1970 # Reset. 1971 #self.interpreter.reset() 1972 1973 ## Set Experiments. 1974 model_create = 'B14' 1975 #model_create = 'NS CPMG 2-site expanded' 1976 model_analyse = 'NS CPMG 2-site 3D' 1977 1978 # Exp 1 1979 sfrq_1 = 599.8908617*1E6 1980 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 1981 time_T2_1 = 0.06 1982 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 1983 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1984 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1985 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 1986 1987 sfrq_2 = 499.8908617*1E6 1988 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 1989 time_T2_2 = 0.05 1990 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 1991 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1992 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1993 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 1994 1995 # Collect all exps 1996 exps = [exp_1, exp_2] 1997 1998 spins = [ 1999 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2000 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2001 ] 2002 2003 # Collect the data to be used. 2004 ds.data = [model_create, model_analyse, spins, exps] 2005 2006 # The tmp directory. None is the local directory. 2007 ds.tmpdir = ds.tmpdir 2008 2009 # The results directory. None is the local directory. 2010 #ds.resdir = None 2011 ds.resdir = ds.tmpdir 2012 2013 # Do r20_from_min_r2eff ?. 2014 ds.r20_from_min_r2eff = True 2015 2016 # Remove insignificant level. 2017 ds.insignificance = 0.0 2018 2019 # The grid search size (the number of increments per dimension). 2020 ds.GRID_INC = None 2021 2022 # The do clustering. 2023 ds.do_cluster = True 2024 2025 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2026 # The default value is 1e-25. 2027 ds.set_func_tol = 1e-1 2028 2029 # The maximum number of iterations. 2030 # The default value is 1e7. 2031 ds.set_max_iter = 1000 2032 2033 # The verbosity level. 2034 ds.verbosity = 1 2035 2036 # The rel_change WARNING level. 2037 ds.rel_change = 0.05 2038 2039 # The plot_curves. 2040 ds.plot_curves = False 2041 2042 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2043 ds.sherekhan_input = False 2044 2045 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2046 ds.opendx = False 2047 2048 # The set r2eff err. 2049 ds.r2eff_err = 0.1 2050 2051 # The print result info. 2052 ds.print_res = True 2053 2054 # Execute the script. 2055 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2056 2057 cur_spins = ds.data[2] 2058 # Compare results. 2059 for i in range(len(cur_spins)): 2060 res_name, res_num, spin_name, params = cur_spins[i] 2061 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2062 cur_spin = return_spin(cur_spin_id) 2063 2064 grid_params = ds.grid_results[i][3] 2065 2066 # Extract the clust results. 2067 min_params = ds.clust_results[i][3] 2068 # Now read the parameters. 2069 print("For spin: '%s'"%cur_spin_id) 2070 for mo_param in cur_spin.params: 2071 # The R2 is a dictionary, depending on spectrometer frequency. 2072 if isinstance(getattr(cur_spin, mo_param), dict): 2073 grid_r2 = grid_params[mo_param] 2074 min_r2 = min_params[mo_param] 2075 set_r2 = params[mo_param] 2076 for key, val in set_r2.items(): 2077 grid_r2_frq = grid_r2[key] 2078 min_r2_frq = min_r2[key] 2079 set_r2_frq = set_r2[key] 2080 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2081 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2082 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2083 if rel_change > ds.rel_change: 2084 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2085 print("###################################") 2086 2087 ## Make test on R2. 2088 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2089 else: 2090 grid_val = grid_params[mo_param] 2091 min_val = min_params[mo_param] 2092 set_val = params[mo_param] 2093 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2094 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2095 if rel_change > ds.rel_change: 2096 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2097 print("###################################") 2098 2099 ## Make test on parameters. 2100 if mo_param == 'dw': 2101 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2102 elif mo_param == 'kex': 2103 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2104 elif mo_param == 'pA': 2105 self.assertAlmostEqual(set_val, min_val, 2)
2106 2107
2109 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2110 2111 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2112 2113 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2114 """ 2115 2116 # Reset. 2117 #self.interpreter.reset() 2118 2119 ## Set Experiments. 2120 model_create = 'B14' 2121 #model_create = 'NS CPMG 2-site expanded' 2122 model_analyse = 'NS CPMG 2-site star' 2123 2124 # Exp 1 2125 sfrq_1 = 599.8908617*1E6 2126 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2127 time_T2_1 = 0.06 2128 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2129 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2130 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2131 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2132 2133 sfrq_2 = 499.8908617*1E6 2134 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2135 time_T2_2 = 0.05 2136 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2137 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2138 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2139 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2140 2141 # Collect all exps 2142 exps = [exp_1, exp_2] 2143 2144 spins = [ 2145 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2146 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2147 ] 2148 2149 # Collect the data to be used. 2150 ds.data = [model_create, model_analyse, spins, exps] 2151 2152 # The tmp directory. None is the local directory. 2153 ds.tmpdir = ds.tmpdir 2154 2155 # The results directory. None is the local directory. 2156 #ds.resdir = None 2157 ds.resdir = ds.tmpdir 2158 2159 # Do r20_from_min_r2eff ?. 2160 ds.r20_from_min_r2eff = True 2161 2162 # Remove insignificant level. 2163 ds.insignificance = 0.0 2164 2165 # The grid search size (the number of increments per dimension). 2166 ds.GRID_INC = None 2167 2168 # The do clustering. 2169 ds.do_cluster = True 2170 2171 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2172 # The default value is 1e-25. 2173 ds.set_func_tol = 1e-1 2174 2175 # The maximum number of iterations. 2176 # The default value is 1e7. 2177 ds.set_max_iter = 1000 2178 2179 # The verbosity level. 2180 ds.verbosity = 1 2181 2182 # The rel_change WARNING level. 2183 ds.rel_change = 0.05 2184 2185 # The plot_curves. 2186 ds.plot_curves = False 2187 2188 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2189 ds.sherekhan_input = False 2190 2191 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2192 ds.opendx = False 2193 2194 # The set r2eff err. 2195 ds.r2eff_err = 0.1 2196 2197 # The print result info. 2198 ds.print_res = True 2199 2200 # Execute the script. 2201 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2202 2203 cur_spins = ds.data[2] 2204 # Compare results. 2205 for i in range(len(cur_spins)): 2206 res_name, res_num, spin_name, params = cur_spins[i] 2207 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2208 cur_spin = return_spin(cur_spin_id) 2209 2210 grid_params = ds.grid_results[i][3] 2211 2212 # Extract the clust results. 2213 min_params = ds.clust_results[i][3] 2214 # Now read the parameters. 2215 print("For spin: '%s'"%cur_spin_id) 2216 for mo_param in cur_spin.params: 2217 # The R2 is a dictionary, depending on spectrometer frequency. 2218 if isinstance(getattr(cur_spin, mo_param), dict): 2219 grid_r2 = grid_params[mo_param] 2220 min_r2 = min_params[mo_param] 2221 set_r2 = params[mo_param] 2222 for key, val in set_r2.items(): 2223 grid_r2_frq = grid_r2[key] 2224 min_r2_frq = min_r2[key] 2225 set_r2_frq = set_r2[key] 2226 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2227 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2228 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2229 if rel_change > ds.rel_change: 2230 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2231 print("###################################") 2232 2233 ## Make test on R2. 2234 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2235 else: 2236 grid_val = grid_params[mo_param] 2237 min_val = min_params[mo_param] 2238 set_val = params[mo_param] 2239 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2240 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2241 if rel_change > ds.rel_change: 2242 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2243 print("###################################") 2244 2245 ## Make test on parameters. 2246 if mo_param == 'dw': 2247 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2248 elif mo_param == 'kex': 2249 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2250 elif mo_param == 'pA': 2251 self.assertAlmostEqual(set_val, min_val, 2)
2252 2253
2255 """Test synthetic cpmg data. 2256 2257 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2258 """ 2259 2260 # Reset. 2261 #self.interpreter.reset() 2262 2263 ## Set Experiments. 2264 model_create = 'NS CPMG 2-site 3D' 2265 #model_create = 'NS CPMG 2-site expanded' 2266 model_analyse = 'CR72' 2267 # Exp 1 2268 sfrq_1 = 599.8908617*1E6 2269 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2270 time_T2_1 = 0.06 2271 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2272 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2273 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2274 2275 sfrq_2 = 499.8908617*1E6 2276 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2277 time_T2_2 = 0.05 2278 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2279 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2280 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2281 2282 # Collect all exps 2283 exps = [exp_1, exp_2] 2284 2285 spins = [ 2286 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2287 ] 2288 2289 # Collect the data to be used. 2290 ds.data = [model_create, model_analyse, spins, exps] 2291 2292 # The tmp directory. None is the local directory. 2293 ds.tmpdir = ds.tmpdir 2294 2295 # The results directory. None is the local directory. 2296 #ds.resdir = None 2297 ds.resdir = ds.tmpdir 2298 2299 # Do r20_from_min_r2eff ?. 2300 ds.r20_from_min_r2eff = True 2301 2302 # Remove insignificant level. 2303 ds.insignificance = 0.0 2304 2305 # The grid search size (the number of increments per dimension). 2306 ds.GRID_INC = 8 2307 2308 # The do clustering. 2309 ds.do_cluster = False 2310 2311 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2312 # The default value is 1e-25. 2313 ds.set_func_tol = 1e-9 2314 2315 # The maximum number of iterations. 2316 # The default value is 1e7. 2317 ds.set_max_iter = 1000 2318 2319 # The verbosity level. 2320 ds.verbosity = 1 2321 2322 # The rel_change WARNING level. 2323 ds.rel_change = 0.05 2324 2325 # The plot_curves. 2326 ds.plot_curves = False 2327 2328 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2329 ds.sherekhan_input = False 2330 2331 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2332 ds.opendx = False 2333 2334 # The set r2eff err. 2335 ds.r2eff_err = 0.1 2336 2337 # The print result info. 2338 ds.print_res = False 2339 2340 # Execute the script. 2341 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2342 2343 cur_spins = ds.data[2] 2344 # Compare results. 2345 for i in range(len(cur_spins)): 2346 res_name, res_num, spin_name, params = cur_spins[i] 2347 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2348 cur_spin = return_spin(cur_spin_id) 2349 2350 grid_params = ds.grid_results[i][3] 2351 min_params = ds.min_results[i][3] 2352 # Now read the parameters. 2353 print("For spin: '%s'"%cur_spin_id) 2354 for mo_param in cur_spin.params: 2355 # The R2 is a dictionary, depending on spectrometer frequency. 2356 if isinstance(getattr(cur_spin, mo_param), dict): 2357 grid_r2 = grid_params[mo_param] 2358 min_r2 = min_params[mo_param] 2359 set_r2 = params[mo_param] 2360 for key, val in set_r2.items(): 2361 grid_r2_frq = grid_r2[key] 2362 min_r2_frq = min_r2[key] 2363 set_r2_frq = set_r2[key] 2364 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2365 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2366 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2367 if rel_change > ds.rel_change: 2368 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2369 print("###################################") 2370 2371 ## Make test on R2. 2372 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2373 else: 2374 grid_val = grid_params[mo_param] 2375 min_val = min_params[mo_param] 2376 set_val = params[mo_param] 2377 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2378 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2379 if rel_change > ds.rel_change: 2380 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2381 print("###################################") 2382 2383 ## Make test on parameters. 2384 if mo_param == 'dw': 2385 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2386 elif mo_param == 'kex': 2387 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2388 elif mo_param == 'pA': 2389 self.assertAlmostEqual(set_val, min_val, 3)
2390 2391
2393 """Test synthetic cpmg data. 2394 2395 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2396 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2397 """ 2398 2399 # Reset. 2400 #self.interpreter.reset() 2401 2402 ## Set Experiments. 2403 model_create = 'NS CPMG 2-site 3D' 2404 #model_create = 'NS CPMG 2-site expanded' 2405 model_analyse = 'B14' 2406 # Exp 1 2407 sfrq_1 = 599.8908617*1E6 2408 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2409 time_T2_1 = 0.06 2410 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2411 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2412 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2413 2414 sfrq_2 = 499.8908617*1E6 2415 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2416 time_T2_2 = 0.05 2417 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2418 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2419 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2420 2421 # Collect all exps 2422 exps = [exp_1, exp_2] 2423 2424 spins = [ 2425 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2426 ] 2427 2428 # Collect the data to be used. 2429 ds.data = [model_create, model_analyse, spins, exps] 2430 2431 # The tmp directory. None is the local directory. 2432 ds.tmpdir = ds.tmpdir 2433 2434 # The results directory. None is the local directory. 2435 #ds.resdir = None 2436 ds.resdir = ds.tmpdir 2437 2438 # Do r20_from_min_r2eff ?. 2439 ds.r20_from_min_r2eff = True 2440 2441 # Remove insignificant level. 2442 ds.insignificance = 0.0 2443 2444 # The grid search size (the number of increments per dimension). 2445 ds.GRID_INC = 8 2446 2447 # The do clustering. 2448 ds.do_cluster = False 2449 2450 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2451 # The default value is 1e-25. 2452 ds.set_func_tol = 1e-9 2453 2454 # The maximum number of iterations. 2455 # The default value is 1e7. 2456 ds.set_max_iter = 1000 2457 2458 # The verbosity level. 2459 ds.verbosity = 1 2460 2461 # The rel_change WARNING level. 2462 ds.rel_change = 0.05 2463 2464 # The plot_curves. 2465 ds.plot_curves = False 2466 2467 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2468 ds.sherekhan_input = False 2469 2470 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2471 ds.opendx = False 2472 2473 # The set r2eff err. 2474 ds.r2eff_err = 0.1 2475 2476 # The print result info. 2477 ds.print_res = False 2478 2479 # Execute the script. 2480 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2481 2482 cur_spins = ds.data[2] 2483 # Compare results. 2484 for i in range(len(cur_spins)): 2485 res_name, res_num, spin_name, params = cur_spins[i] 2486 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2487 cur_spin = return_spin(cur_spin_id) 2488 2489 grid_params = ds.grid_results[i][3] 2490 min_params = ds.min_results[i][3] 2491 # Now read the parameters. 2492 print("For spin: '%s'"%cur_spin_id) 2493 for mo_param in cur_spin.params: 2494 # The R2 is a dictionary, depending on spectrometer frequency. 2495 if isinstance(getattr(cur_spin, mo_param), dict): 2496 grid_r2 = grid_params[mo_param] 2497 min_r2 = min_params[mo_param] 2498 set_r2 = params[mo_param] 2499 for key, val in set_r2.items(): 2500 grid_r2_frq = grid_r2[key] 2501 min_r2_frq = min_r2[key] 2502 set_r2_frq = set_r2[key] 2503 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2504 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2505 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2506 if rel_change > ds.rel_change: 2507 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2508 print("###################################") 2509 2510 ## Make test on R2. 2511 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2512 else: 2513 grid_val = grid_params[mo_param] 2514 min_val = min_params[mo_param] 2515 set_val = params[mo_param] 2516 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2517 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2518 if rel_change > ds.rel_change: 2519 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2520 print("###################################") 2521 2522 ## Make test on parameters. 2523 if mo_param == 'dw': 2524 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2525 elif mo_param == 'kex': 2526 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2527 elif mo_param == 'pA': 2528 self.assertAlmostEqual(set_val, min_val, 6)
2529 2530
2532 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2533 2534 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2535 """ 2536 2537 # Reset. 2538 #self.interpreter.reset() 2539 2540 ## Set Experiments. 2541 model_create = 'NS CPMG 2-site 3D' 2542 #model_create = 'NS CPMG 2-site expanded' 2543 model_analyse = 'CR72' 2544 2545 # Exp 1 2546 sfrq_1 = 599.8908617*1E6 2547 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2548 time_T2_1 = 0.06 2549 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2550 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2551 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2552 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2553 2554 sfrq_2 = 499.8908617*1E6 2555 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2556 time_T2_2 = 0.05 2557 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2558 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2559 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2560 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2561 2562 # Collect all exps 2563 exps = [exp_1, exp_2] 2564 2565 spins = [ 2566 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2567 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2568 ] 2569 2570 # Collect the data to be used. 2571 ds.data = [model_create, model_analyse, spins, exps] 2572 2573 # The tmp directory. None is the local directory. 2574 ds.tmpdir = ds.tmpdir 2575 2576 # The results directory. None is the local directory. 2577 #ds.resdir = None 2578 ds.resdir = ds.tmpdir 2579 2580 # Do r20_from_min_r2eff ?. 2581 ds.r20_from_min_r2eff = True 2582 2583 # Remove insignificant level. 2584 ds.insignificance = 0.0 2585 2586 # The grid search size (the number of increments per dimension). 2587 ds.GRID_INC = 13 2588 2589 # The do clustering. 2590 ds.do_cluster = True 2591 2592 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2593 # The default value is 1e-25. 2594 ds.set_func_tol = 1e-8 2595 2596 # The maximum number of iterations. 2597 # The default value is 1e7. 2598 ds.set_max_iter = 10000 2599 2600 # The verbosity level. 2601 ds.verbosity = 1 2602 2603 # The rel_change WARNING level. 2604 ds.rel_change = 0.05 2605 2606 # The plot_curves. 2607 ds.plot_curves = False 2608 2609 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2610 ds.sherekhan_input = False 2611 2612 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2613 ds.opendx = False 2614 2615 # The set r2eff err. 2616 ds.r2eff_err = 0.1 2617 2618 # The print result info. 2619 ds.print_res = False 2620 2621 # Execute the script. 2622 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2623 2624 cur_spins = ds.data[2] 2625 # Compare results. 2626 for i in range(len(cur_spins)): 2627 res_name, res_num, spin_name, params = cur_spins[i] 2628 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2629 cur_spin = return_spin(cur_spin_id) 2630 2631 grid_params = ds.grid_results[i][3] 2632 2633 # Extract the clust results. 2634 min_params = ds.clust_results[i][3] 2635 # Now read the parameters. 2636 print("For spin: '%s'"%cur_spin_id) 2637 for mo_param in cur_spin.params: 2638 # The R2 is a dictionary, depending on spectrometer frequency. 2639 if isinstance(getattr(cur_spin, mo_param), dict): 2640 grid_r2 = grid_params[mo_param] 2641 min_r2 = min_params[mo_param] 2642 set_r2 = params[mo_param] 2643 for key, val in set_r2.items(): 2644 grid_r2_frq = grid_r2[key] 2645 min_r2_frq = min_r2[key] 2646 set_r2_frq = set_r2[key] 2647 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2648 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2649 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2650 if rel_change > ds.rel_change: 2651 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2652 print("###################################") 2653 2654 ## Make test on R2. 2655 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2656 else: 2657 grid_val = grid_params[mo_param] 2658 min_val = min_params[mo_param] 2659 set_val = params[mo_param] 2660 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2661 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2662 if rel_change > ds.rel_change: 2663 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2664 print("###################################") 2665 2666 ## Make test on parameters. 2667 if mo_param == 'dw': 2668 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2669 elif mo_param == 'kex': 2670 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2671 elif mo_param == 'pA': 2672 self.assertAlmostEqual(set_val, min_val, 2)
2673 2674
2676 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2677 2678 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2679 """ 2680 2681 # Reset. 2682 #self.interpreter.reset() 2683 2684 ## Set Experiments. 2685 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2686 model_analyse = 'CR72' 2687 # Exp 1 2688 sfrq_1 = 599.8908617*1E6 2689 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2690 time_T2_1 = 0.06 2691 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2692 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2693 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2694 2695 sfrq_2 = 499.8908617*1E6 2696 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2697 time_T2_2 = 0.05 2698 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2699 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2700 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2701 2702 # Collect all exps 2703 exps = [exp_1, exp_2] 2704 2705 spins = [ 2706 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2707 ] 2708 2709 # Collect the data to be used. 2710 ds.data = [model_create, model_analyse, spins, exps] 2711 2712 # The tmp directory. None is the local directory. 2713 ds.tmpdir = ds.tmpdir 2714 2715 # The results directory. None is the local directory. 2716 #ds.resdir = None 2717 ds.resdir = ds.tmpdir 2718 2719 # Do r20_from_min_r2eff ?. 2720 ds.r20_from_min_r2eff = True 2721 2722 # Remove insignificant level. 2723 ds.insignificance = 0.0 2724 2725 # The grid search size (the number of increments per dimension). 2726 ds.GRID_INC = None 2727 2728 # The do clustering. 2729 ds.do_cluster = False 2730 2731 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2732 # The default value is 1e-25. 2733 ds.set_func_tol = 1e-9 2734 2735 # The maximum number of iterations. 2736 # The default value is 1e7. 2737 ds.set_max_iter = 1000 2738 2739 # The verbosity level. 2740 ds.verbosity = 1 2741 2742 # The rel_change WARNING level. 2743 ds.rel_change = 0.05 2744 2745 # The plot_curves. 2746 ds.plot_curves = False 2747 2748 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2749 ds.sherekhan_input = False 2750 2751 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2752 ds.opendx = False 2753 2754 # The set r2eff err. 2755 ds.r2eff_err = 0.1 2756 2757 # The print result info. 2758 ds.print_res = False 2759 2760 # Execute the script. 2761 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2762 2763 # Get the spins. 2764 cur_spins = ds.data[2] 2765 2766 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2767 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2768 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2769 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2770 2771 # Copy R2eff, but not the original parameters 2772 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2773 2774 # Then select model. 2775 self.interpreter.relax_disp.select_model(model=model_analyse) 2776 2777 # Define dx.map settings. 2778 ds.dx_inc = 4 2779 ds.dx_params = ['dw', 'pA', 'kex'] 2780 2781 res_name, res_num, spin_name, params = cur_spins[0] 2782 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2783 cur_spin = return_spin(cur_spin_id) 2784 2785 print("Params for dx map is") 2786 print(ds.dx_params) 2787 print("Point param for dx map is") 2788 print(ds.dx_set_val) 2789 cur_model = model_analyse.replace(' ', '_') 2790 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2791 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2792 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point) 2793 2794 ## Check for file creation 2795 # Set filepaths. 2796 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2797 map_net = ds.tmpdir+sep+file_name_map+".net" 2798 map_general = ds.tmpdir+sep+file_name_map+".general" 2799 2800 point_general = ds.tmpdir+sep+file_name_point+".general" 2801 point_point = ds.tmpdir+sep+file_name_point 2802 2803 # Test the files exists. 2804 self.assert_(access(map_cfg, F_OK)) 2805 self.assert_(access(map_net, F_OK)) 2806 self.assert_(access(map_general, F_OK)) 2807 self.assert_(access(point_general, F_OK)) 2808 self.assert_(access(point_point, F_OK)) 2809 2810 # Open the files for testing. 2811 # Check the cfg file. 2812 print("\nChecking the dx map .cfg file.") 2813 res_file = [ 2814 '//'+"\n", 2815 '//'+"\n", 2816 '// time: Thu May 8 18:55:31 2014'+"\n", 2817 '//'+"\n", 2818 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2819 '//'+"\n", 2820 '//'+"\n", 2821 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2822 '// title: value = Control Panel'+"\n", 2823 '//'+"\n", 2824 '// workspace: width = 251, height = 142'+"\n", 2825 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2826 '//'+"\n", 2827 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2828 '// selections: maximum = 2, current = 0 '+"\n", 2829 '// option[0]: name = "Colour", value = 1'+"\n", 2830 '// option[1]: name = "Grey", value = 2'+"\n", 2831 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2832 '// label: value = Colour Selector'+"\n", 2833 '//'+"\n", 2834 '// node Image[3]:'+"\n", 2835 '// title: value = Surface'+"\n", 2836 '// depth: value = 24'+"\n", 2837 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2838 ] 2839 file = open(map_cfg, 'r') 2840 lines = file.readlines() 2841 file.close() 2842 for i in range(len(res_file)): 2843 # Skip time point 2844 if i == 2: 2845 continue 2846 self.assertEqual(res_file[i], lines[i]) 2847 2848 print("\nChecking the dx map .general file.") 2849 res_file = [ 2850 'file = CR72_map_1_N'+"\n", 2851 'grid = 5 x 5 x 5'+"\n", 2852 'format = ascii'+"\n", 2853 'interleaving = field'+"\n", 2854 'majority = row'+"\n", 2855 'field = data'+"\n", 2856 'structure = scalar'+"\n", 2857 'type = float'+"\n", 2858 'dependency = positions'+"\n", 2859 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2860 ''+"\n", 2861 'end'+"\n", 2862 ] 2863 file = open(map_general, 'r') 2864 lines = file.readlines() 2865 file.close() 2866 for i in range(len(res_file)): 2867 # Skip time point 2868 #if i == 2: 2869 # continue 2870 self.assertEqual(res_file[i], lines[i]) 2871 2872 print("\nChecking the dx point .general file.") 2873 res_file = [ 2874 'file = CR72_point_1_N'+"\n", 2875 'points = 2'+"\n", 2876 'format = ascii'+"\n", 2877 'interleaving = field'+"\n", 2878 'field = locations, field0'+"\n", 2879 'structure = 3-vector, scalar'+"\n", 2880 'type = float, float'+"\n", 2881 ''+"\n", 2882 'end'+"\n", 2883 ] 2884 file = open(point_general, 'r') 2885 lines = file.readlines() 2886 file.close() 2887 for i in range(len(res_file)): 2888 # Skip time point 2889 #if i == 2: 2890 # continue 2891 self.assertEqual(res_file[i], lines[i]) 2892 2893 print("\nChecking the dx point point file.") 2894 res_file = [ 2895 '0.8 3.92 0.39964 1'+"\n", 2896 '0.76981 3.9169 0.41353 1'+"\n", 2897 ] 2898 file = open(point_point, 'r') 2899 lines = file.readlines() 2900 file.close() 2901 for i in range(len(res_file)): 2902 # Skip time point 2903 #if i == 2: 2904 # continue 2905 self.assertEqual(res_file[i], lines[i])
2906 2907
2909 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 2910 2911 # Reset. 2912 self.interpreter.reset() 2913 2914 # Load the base data. 2915 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 2916 self.interpreter.state.load(data_path+sep+'r2eff_values') 2917 2918 # The type. 2919 curve_type = get_curve_type(id='500_133.33.in') 2920 self.assertEqual(curve_type, 'fixed time')
2921 2922
2923 - def test_curve_type_r1rho_exponential(self, model=None):
2924 """Test the curve type detection using the 'M61' exponential test data.""" 2925 2926 # Reset. 2927 self.interpreter.reset() 2928 2929 # Load the base data. 2930 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 2931 self.interpreter.state.load(data_path+sep+'r2eff_values') 2932 2933 # The type. 2934 curve_type = get_curve_type(id='nu_2000_ncyc9') 2935 self.assertEqual(curve_type, 'exponential')
2936 2937
2938 - def test_curve_type_r1rho_fixed_time(self, model=None):
2939 """Test the curve type detection using the 'TP02' fixed time test data.""" 2940 2941 # Reset. 2942 self.interpreter.reset() 2943 2944 # Load the base data. 2945 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 2946 self.interpreter.state.load(data_path+sep+'r2eff_values') 2947 2948 # The type. 2949 curve_type = get_curve_type(id='nu_1000.0_500MHz') 2950 self.assertEqual(curve_type, 'fixed time')
2951 2952
2953 - def test_dpl94_data_to_dpl94(self):
2954 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 2955 2956 # Fixed time variable. 2957 ds.fixed = True 2958 2959 # Execute the script. 2960 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 2961 2962 # The original parameters. 2963 i0 = [100000.0, 20000.0] 2964 r1rho_prime = [2.25, 24.0] 2965 pA = 0.7 2966 kex = 1000.0 2967 delta_omega = [1.0, 2.0] 2968 phi_ex = [] 2969 for i in range(2): 2970 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 2971 2972 # Switch to the 'DPL94' model data pipe, then check for each spin. 2973 self.interpreter.pipe.switch('DPL94 - relax_disp') 2974 spin_index = 0 2975 for spin, spin_id in spin_loop(return_id=True): 2976 # Printout. 2977 print("\nSpin %s." % spin_id) 2978 2979 # Check the fitted parameters. 2980 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 2981 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 2982 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 2983 2984 # Increment the spin index. 2985 spin_index += 1
2986 2987
2988 - def test_dx_map_clustered(self):
2989 """Test making dx_map for residues under clustered calculation. 2990 2991 This uses CPMG data from: 2992 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 2993 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 2994 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 2995 """ 2996 2997 # Define path to data 2998 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 2999 3000 # Read data. 3001 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3002 3003 # Get residue of interest. 3004 cur_spin_id = ":%i@%s"%(52, 'N') 3005 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3006 3007 # Get the spin container. 3008 cur_spin = return_spin(cur_spin_id) 3009 3010 # Get the chi2 value 3011 pre_chi2 = cur_spin.chi2 3012 3013 # Then do a local minimisation. 3014 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3015 self.interpreter.minimise.calculate() 3016 3017 # Get the chi2 value after calculation. 3018 calc_chi2 = cur_spin.chi2 3019 3020 # Assert calculation is equal. 3021 self.assertAlmostEqual(pre_chi2, calc_chi2) 3022 3023 # Define dx.map settings. 3024 dx_inc = 2 3025 dx_inc_sides = dx_inc / 2 3026 3027 dx_params = ['dw', 'pA', 'kex'] 3028 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3029 3030 print("Params for dx map is") 3031 print(dx_params) 3032 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3033 print(dx_point_clustered_min) 3034 3035 # Define file_names. 3036 cur_model = 'CR72' 3037 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3038 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3039 3040 # Step-size of parameter is 10 % 3041 param_delta = 0.1 3042 3043 # Determine bounds for lower and upper 3044 lower = [] 3045 upper = [] 3046 for i, param_val in enumerate(dx_point_clustered_min): 3047 param = dx_params[0] 3048 step_val = param_delta * param_val 3049 step_length = step_val * dx_inc_sides 3050 3051 # Calculate value 3052 low_val = param_val - step_length 3053 lower.append(low_val) 3054 3055 upp_val = param_val + step_length 3056 upper.append(upp_val) 3057 3058 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3059 3060 # If the number of increments are 2, there will be 3 point calculations per parameter. 3061 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3062 dx_param_indexes = dx_inc + 1 3063 dx_point_index = dx_inc_sides + 1 3064 3065 # Find the line number. 3066 line = 1 3067 for i in range(1, dx_param_indexes + 1): 3068 for j in range(1, dx_param_indexes + 1): 3069 for k in range(1, dx_param_indexes + 1): 3070 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3071 line_chi2 = line 3072 # Add to line counter. 3073 line += 1 3074 3075 # Define temporary folder. 3076 result_dir = self.tmpdir 3077 3078 # For testing. 3079 #result_dir = None 3080 #lower = None 3081 #upper = None 3082 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3083 3084 3085 # Then do the map. 3086 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3087 3088 # Print where to locate values. 3089 nr_chi2_val = dx_param_indexes**3 3090 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3091 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3092 3093 ## Check for file creation 3094 # Set filepaths. 3095 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3096 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3097 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3098 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3099 3100 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3101 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3102 3103 # Test the files exists. 3104 self.assert_(access(map_cfg, F_OK)) 3105 self.assert_(access(map_net, F_OK)) 3106 self.assert_(access(map_general, F_OK)) 3107 self.assert_(access(point_general, F_OK)) 3108 self.assert_(access(point_point, F_OK)) 3109 3110 # Open the file, and assert the chi2 value is as expected. 3111 get_data = extract_data(file=map_name) 3112 3113 # Extract line 0, column 0. 3114 test = float(get_data[line_chi2-1][0]) 3115 3116 # Assert. 3117 self.assertAlmostEqual(test, pre_chi2, 6)
3118 3119
3120 - def test_estimate_r2eff_err(self):
3121 """Test the user function for estimating R2eff errors from exponential curve fitting. 3122 3123 This follows Task 7822. 3124 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3125 3126 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3127 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3128 """ 3129 3130 # Cluster residues 3131 cluster_ids = [ 3132 ":13@N", 3133 ":15@N", 3134 ":16@N", 3135 ":25@N", 3136 ":26@N", 3137 ":28@N", 3138 ":39@N", 3139 ":40@N", 3140 ":41@N", 3141 ":43@N", 3142 ":44@N", 3143 ":45@N", 3144 ":49@N", 3145 ":52@N", 3146 ":53@N"] 3147 3148 # Load the data. 3149 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3150 3151 # The dispersion models. 3152 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3153 3154 # The grid search size (the number of increments per dimension). 3155 GRID_INC = None 3156 3157 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3158 MC_NUM = 3 3159 3160 # Model selection technique. 3161 MODSEL = 'AIC' 3162 3163 # Execute the auto-analysis (fast). 3164 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3165 OPT_FUNC_TOL = 1e-25 3166 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3167 OPT_MAX_ITERATIONS = 10000000 3168 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3169 3170 result_dir_name = ds.tmpdir 3171 3172 # Make all spins free 3173 for curspin in cluster_ids: 3174 self.interpreter.relax_disp.cluster('free spins', curspin) 3175 # Shut them down 3176 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3177 3178 # Select only a subset of spins for global fitting 3179 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3180 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3181 3182 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3183 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3184 3185 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3186 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3187 3188 # Set the model. 3189 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3190 3191 # Check if intensity errors have already been calculated. 3192 check_intensity_errors() 3193 3194 # Do a grid search. 3195 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3196 3197 # Minimise. 3198 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3199 3200 # Estimate R2eff errors. 3201 self.interpreter.relax_disp.r2eff_err_estimate() 3202 3203 r1_fit = True 3204 3205 # Run the analysis. 3206 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3207 3208 # Verify the data. 3209 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3210 3211
3213 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3214 3215 This follows Task 7822. 3216 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3217 3218 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3219 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3220 """ 3221 3222 # Cluster residues 3223 cluster_ids = [ 3224 ":13@N", 3225 ":15@N", 3226 ":16@N", 3227 ":25@N", 3228 ":26@N", 3229 ":28@N", 3230 ":39@N", 3231 ":40@N", 3232 ":41@N", 3233 ":43@N", 3234 ":44@N", 3235 ":45@N", 3236 ":49@N", 3237 ":52@N", 3238 ":53@N"] 3239 3240 # Load the data. 3241 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3242 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3243 3244 # Set pipe name, bundle and type. 3245 pipe_name = 'base pipe' 3246 pipe_bundle = 'relax_disp' 3247 pipe_type = 'relax_disp' 3248 3249 # Create the data pipe. 3250 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3251 3252 file = data_path + '1_setup_r1rho_GUI.py' 3253 self.interpreter.script(file=file, dir=None) 3254 3255 # The dispersion models. 3256 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3257 3258 # The grid search size (the number of increments per dimension). 3259 GRID_INC = None 3260 3261 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3262 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3263 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3264 EXP_MC_NUM = -1 3265 3266 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3267 MC_NUM = 3 3268 3269 # Model selection technique. 3270 MODSEL = 'AIC' 3271 3272 # Execute the auto-analysis (fast). 3273 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3274 OPT_FUNC_TOL = 1e-25 3275 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3276 OPT_MAX_ITERATIONS = 10000000 3277 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3278 3279 # Make all spins free 3280 #for curspin in cluster_ids: 3281 # self.interpreter.relax_disp.cluster('free spins', curspin) 3282 # # Shut them down 3283 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3284 3285 # Make all spins free 3286 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3287 3288 # Select only a subset of spins for global fitting 3289 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3290 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3291 3292 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3293 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3294 3295 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3296 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3297 3298 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3299 print(spin_id) 3300 3301 result_dir_name = self.tmpdir 3302 r1_fit = True 3303 3304 # Run the analysis. 3305 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3306 3307 # Verify the data. 3308 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3309 3310
3312 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3313 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3314 3315 This follows Task 7822. 3316 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3317 3318 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3319 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3320 3321 NOTE: The difference in the methods was due to a bug in relax! 3322 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3323 3324 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3325 """ 3326 3327 # Define data path. 3328 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3329 3330 # Create pipe. 3331 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3332 3333 # Read results for 2000 MC simulations. 3334 self.interpreter.results.read(prev_data_path + sep + 'results') 3335 3336 # Start dic. 3337 my_dic = {} 3338 param_key_list = [] 3339 3340 # Do boot strapping ? 3341 do_boot = True 3342 if do_boot: 3343 min_algor = 'Newton' 3344 min_options = () 3345 sim_boot = 200 3346 scaling_list = [1.0, 1.0] 3347 3348 # First check sim values. 3349 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3350 # Add key to dic. 3351 my_dic[spin_id] = {} 3352 3353 # Loop over sim. 3354 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3355 # Loop over all exp type. 3356 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3357 # Generate the param_key. 3358 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3359 r2eff_sim_point = r2eff_sim[param_key] 3360 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3361 3362 # Assert point are higher than 0.0. 3363 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3364 #print(point_info) 3365 self.assert_(r2eff_sim_point > 0.0) 3366 self.assert_(i0_sim_point > 0.0) 3367 3368 # Get the data. 3369 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3370 # Generate spin string. 3371 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3372 3373 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3374 # Generate the param_key. 3375 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3376 3377 # Loop over all sim, and collect data. 3378 r2eff_sim_l = [] 3379 i0_sim_l = [] 3380 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3381 i0_sim = cur_spin.i0_sim[i] 3382 3383 r2eff_sim_i = r2eff_sim[param_key] 3384 r2eff_sim_l.append(r2eff_sim_i) 3385 i0_sim_i = i0_sim[param_key] 3386 i0_sim_l.append(i0_sim_i) 3387 3388 # Take the standard deviation of all values. 3389 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3390 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3391 3392 # Append key. 3393 param_key_list.append(param_key) 3394 3395 # Add key to dic. 3396 my_dic[spin_id][param_key] = {} 3397 3398 # Get the value. 3399 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3400 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3401 i0 = getattr(cur_spin, 'i0')[param_key] 3402 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3403 3404 # Save to dic. 3405 my_dic[spin_id][param_key]['r2eff'] = r2eff 3406 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3407 my_dic[spin_id][param_key]['i0'] = i0 3408 my_dic[spin_id][param_key]['i0_err'] = i0_err 3409 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3410 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3411 3412 # Assert values are equal 3413 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3414 self.assertAlmostEqual(i0_sim_err, i0_err) 3415 3416 if do_boot: 3417 values = [] 3418 errors = [] 3419 times = [] 3420 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3421 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3422 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3423 times.append(time) 3424 3425 # Convert to numpy array. 3426 values = asarray(values) 3427 errors = asarray(errors) 3428 times = asarray(times) 3429 3430 R_m_sim_l = [] 3431 I0_m_sim_l = [] 3432 for j in range(sim_boot): 3433 if j in range(0, 100000, 100): 3434 print("Simulation %i"%j) 3435 # Start minimisation. 3436 3437 # Produce errors 3438 I_err = [] 3439 for j, error in enumerate(errors): 3440 I_error = gauss(values[j], error) 3441 I_err.append(I_error) 3442 # Convert to numpy array. 3443 I_err = asarray(I_err) 3444 3445 x0 = [r2eff, i0] 3446 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3447 3448 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3449 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3450 R_m_sim_l.append(R_m_sim_j) 3451 I0_m_sim_l.append(I0_m_sim_j) 3452 3453 # Get stats on distribution. 3454 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3455 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3456 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3457 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3458 3459 3460 # A new data pipe. 3461 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3462 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3463 3464 # Delete old errors. 3465 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3466 delattr(cur_spin, 'r2eff_err') 3467 delattr(cur_spin, 'i0_err') 3468 3469 # Set the model. 3470 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3471 3472 # Estimate R2eff and errors. 3473 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3474 3475 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3476 # Generate spin string. 3477 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3478 3479 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3480 # Generate the param_key. 3481 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3482 3483 # Get the value. 3484 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3485 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3486 i0_est = getattr(cur_spin, 'i0')[param_key] 3487 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3488 3489 # Get from dic. 3490 r2eff = my_dic[spin_id][param_key]['r2eff'] 3491 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3492 i0 = my_dic[spin_id][param_key]['i0'] 3493 i0_err = my_dic[spin_id][param_key]['i0_err'] 3494 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3495 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3496 3497 if do_boot: 3498 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3499 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3500 else: 3501 r2eff_boot_err = 0.0 3502 i0_boot_err = 0.0 3503 3504 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3505 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3506 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3507 3508 3509 # Now do it manually. 3510 estimate_r2eff(method='scipy.optimize.leastsq') 3511 3512 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3513 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3514 3515 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3516 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3517 3518 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3519 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3520 3521 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3522 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3523 3524 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3525 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3526 3527 3528
3529 - def test_exp_fit(self):
3530 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3531 3532 # Execute the script. 3533 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3534 3535 # The original exponential curve parameters. 3536 res_data = [ 3537 [15., 10., 20000., 25000.], 3538 [12., 11., 50000., 51000.], 3539 [17., 9., 100000., 96000.] 3540 ] 3541 3542 # List of parameters which do not belong to the model. 3543 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3544 3545 # Checks for each residue. 3546 for i in range(len(res_data)): 3547 # Printout. 3548 print("\nResidue number %s." % (i+1)) 3549 3550 # Check the fitted parameters. 3551 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3552 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3553 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3554 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3555 3556 # Check the simulation errors. 3557 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3558 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3559 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3560 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3561 3562 # Check that certain parameters are not present. 3563 for param in blacklist: 3564 print("\tChecking for the absence of the '%s' parameter." % param) 3565 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3566 3567 # Check the clustering information. 3568 self.assert_(hasattr(cdp, 'clustering')) 3569 keys = ['free spins', 'cluster'] 3570 for key in keys: 3571 self.assert_(key in cdp.clustering) 3572 self.assert_('test' not in cdp.clustering) 3573 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3574 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3575 3576
3577 - def test_finite_value(self):
3578 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3579 3580 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3581 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3582 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3583 3584 scaling_list = [1.0, 1.0] 3585 setup(num_params=2, num_times=len(times), values=I, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3586 3587 R = - 500. 3588 I0 = 1000. 3589 params = [R, I0] 3590 3591 chi2 = func(params) 3592 3593 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3594 self.assertNotEqual(chi2, inf)
3595 3596
3597 - def test_hansen_catia_input(self):
3598 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3599 3600 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3601 """ 3602 3603 # Load the R2eff results file. 3604 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3605 self.interpreter.results.read(file_name) 3606 self.interpreter.deselect.spin(':4') 3607 3608 # The spin isotopes. 3609 self.interpreter.spin.isotope("15N") 3610 3611 # Generate the input files. 3612 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3613 3614 # Check the r2eff set files. 3615 print("\nChecking the R2eff input set files.") 3616 files = ['data_set_500.inp', 'data_set_500.inp'] 3617 for file in files: 3618 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3619 data_set_500 = [ 3620 "ID=500\n", 3621 "Sfrq = 500\n", 3622 "Temperature = 0.0\n", 3623 "Nucleus = N15\n", 3624 "Couplednucleus = H1\n", 3625 "Time_equil = 0.0\n", 3626 "Pwx_cp = 0.0\n", 3627 "Taub = 0.0\n", 3628 "Time_T2 = 0.03\n", 3629 "Xcar = 0.0\n", 3630 "Seqfil = CW_CPMG\n", 3631 "Minerror = (2.%;0.5/s)\n", 3632 "Basis = (Iph_7)\n", 3633 "Format = (0;1;2)\n", 3634 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3635 "Data = (\n", 3636 " [70N;spin_70_N_500.cpmg];\n", 3637 " [71N;spin_71_N_500.cpmg];\n", 3638 ")\n", 3639 ] 3640 file = open(ds.tmpdir+sep+files[0]) 3641 lines = file.readlines() 3642 file.close() 3643 for i in range(len(data_set_500)): 3644 # Skip the data directory, as this is a random file name. 3645 if i == 14: 3646 continue 3647 3648 self.assertEqual(data_set_500[i], lines[i]) 3649 3650 # Check the r2eff files. 3651 print("\nChecking the R2eff input files.") 3652 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3653 for file in files: 3654 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3655 spin_70_N_500 = [ 3656 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3657 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3658 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3659 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3660 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3661 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3662 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3663 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3664 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3665 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3666 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3667 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3668 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3669 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3670 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3671 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3672 ] 3673 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3674 lines = file.readlines() 3675 file.close() 3676 for i in range(len(lines)): 3677 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3678 for i in range(len(spin_70_N_500)): 3679 self.assertEqual(spin_70_N_500[i], lines[i]) 3680 3681 # Check the main file. 3682 print("\nChecking the main CATIA execution file.") 3683 main_file = [ 3684 "ReadDataset(data_set_500.inp)\n", 3685 "ReadDataset(data_set_800.inp)\n", 3686 "ReadParam_Global(ParamGlobal.inp)\n", 3687 "ReadParam_Local(ParamSet1.inp)\n", 3688 "\n", 3689 "FreeLocalParam(all;Omega;false)\n", 3690 "FreeLocalParam(all;R1iph_500;false)\n", 3691 "FreeLocalParam(all;R1iph_800;false)\n", 3692 "\n", 3693 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3694 "\n", 3695 "PrintParam(output/GlobalParam.fit;global)\n", 3696 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3697 "PrintData(output/)\n", 3698 "\n", 3699 "ChiSq(all;all)\n", 3700 "exit(0)\n" 3701 ] 3702 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3703 lines = file.readlines() 3704 file.close() 3705 for i in range(len(main_file)): 3706 self.assertEqual(main_file[i], lines[i])
3707 3708
3710 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3711 3712 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3713 """ 3714 3715 # Set the model. 3716 ds.models = [ 3717 MODEL_NOREX, 3718 MODEL_LM63, 3719 MODEL_CR72, 3720 MODEL_IT99 3721 ] 3722 3723 # Execute the script. 3724 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3725 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3726 3727 # The R20 keys. 3728 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3729 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3730 3731 # The 'No Rex' model checks. 3732 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3733 spin70 = return_spin(":70") 3734 spin71 = return_spin(":71") 3735 print("\n\nOptimised parameters:\n") 3736 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3737 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3738 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3739 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3740 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3741 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3742 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3743 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3744 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3745 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3746 3747 # The 'LM63' model checks. 3748 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3749 spin70 = return_spin(":70") 3750 spin71 = return_spin(":71") 3751 print("\n\nOptimised parameters:\n") 3752 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3753 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3754 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3755 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3756 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3757 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3758 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3759 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3760 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3761 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3762 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3763 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3764 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3765 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3766 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3767 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3768 3769 # The 'CR72' model checks. 3770 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3771 spin70 = return_spin(":70") 3772 spin71 = return_spin(":71") 3773 print("\n\nOptimised parameters:\n") 3774 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3775 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3776 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3777 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3778 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3779 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3780 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3781 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3782 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3783 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3784 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3785 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3786 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3787 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3788 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3789 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3790 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3791 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3792 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
3793 3794
3796 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3797 3798 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3799 """ 3800 3801 # Set the model and numeric flag. 3802 ds.models = [ 3803 MODEL_NOREX, 3804 MODEL_CR72, 3805 MODEL_NS_CPMG_2SITE_EXPANDED 3806 ] 3807 ds.numeric_only = True 3808 3809 # Execute the script. 3810 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3811 3812 # The R20 keys. 3813 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3814 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3815 3816 # The 'No Rex' model checks. 3817 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3818 spin70 = return_spin(":70") 3819 spin71 = return_spin(":71") 3820 print("\n\nOptimised parameters:\n") 3821 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3822 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3823 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3824 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3825 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3826 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3827 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 3828 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3829 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3830 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 3831 3832 # The 'CR72' model checks. 3833 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3834 spin70 = return_spin(":70") 3835 spin71 = return_spin(":71") 3836 print("\n\nOptimised parameters:\n") 3837 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3838 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3839 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3840 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3841 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3842 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3843 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3844 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3845 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3846 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3847 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3848 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3849 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3850 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3851 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3852 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3853 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3854 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3855 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 3856 3857 # The 'NS CPMG 2-site expanded' model checks. 3858 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 3859 spin70 = return_spin(":70") 3860 spin71 = return_spin(":71") 3861 print("\n\nOptimised parameters:\n") 3862 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3863 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3864 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3865 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3866 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3867 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3868 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3869 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 3870 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 3871 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 3872 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 3873 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 3874 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 3875 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 3876 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 3877 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 3878 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 3879 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 3880 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 3881 3882 # The final data pipe checks. 3883 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 3884 spin70 = return_spin(":70") 3885 spin71 = return_spin(":71") 3886 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 3887 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
3888 3889
3891 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 3892 3893 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3894 """ 3895 3896 # Set the model. 3897 ds.models = [ 3898 MODEL_NOREX, 3899 MODEL_LM63, 3900 MODEL_CR72, 3901 MODEL_IT99 3902 ] 3903 3904 # Execute the script. 3905 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 3906 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 3907 3908 # The R20 keys. 3909 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3910 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3911 3912 # The 'No Rex' model checks. 3913 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3914 spin70 = return_spin(":70") 3915 spin71 = return_spin(":71") 3916 print("\n\nOptimised parameters:\n") 3917 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3918 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3919 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3920 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3921 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3922 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3923 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3924 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3925 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3926 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3927 3928 # The 'LM63' model checks. 3929 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3930 spin70 = return_spin(":70") 3931 spin71 = return_spin(":71") 3932 print("\n\nOptimised parameters:\n") 3933 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3934 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3935 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3936 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3937 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3938 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3939 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3940 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3941 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3942 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3943 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3944 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3945 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3946 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3947 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3948 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3949 3950 # The 'CR72' model checks. 3951 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3952 spin70 = return_spin(":70") 3953 spin71 = return_spin(":71") 3954 print("\n\nOptimised parameters:\n") 3955 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3956 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3957 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3958 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3959 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3960 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3961 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3962 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3963 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3964 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3965 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3966 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3967 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3968 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 3969 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 3970 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 3971 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 3972 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 3973 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
3974 3975
3977 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 3978 3979 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3980 """ 3981 3982 # Set the model. 3983 ds.models = [ 3984 MODEL_R2EFF, 3985 MODEL_NOREX, 3986 MODEL_CR72, 3987 MODEL_NS_CPMG_2SITE_EXPANDED 3988 ] 3989 3990 # Execute the script. 3991 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 3992 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3993 3994 # The R20 keys. 3995 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3996 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3997 3998 # The 'No Rex' model checks. 3999 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4000 spin4 = return_spin(":4") 4001 spin70 = return_spin(":70") 4002 spin71 = return_spin(":71") 4003 print("\n\nOptimised parameters:\n") 4004 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4005 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4006 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4007 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4008 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4009 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4010 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4011 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4012 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4013 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4014 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4015 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4016 4017 # The 'CR72' model checks. 4018 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4019 spin4 = return_spin(":4") 4020 spin70 = return_spin(":70") 4021 spin71 = return_spin(":71") 4022 print("\n\nOptimised parameters:\n") 4023 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4024 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4025 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4026 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4027 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4028 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4029 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4030 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4031 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4032 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4033 self.assertAlmostEqual(spin4.dw, 0.0, 5) 4034 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4035 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4036 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4037 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4038 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4039 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4040 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4041 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4042 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4043 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4044 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 3) 4045 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4046 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4047 4048
4050 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4051 4052 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4053 """ 4054 4055 # Base data setup. 4056 self.setup_hansen_cpmg_data(model='CR72') 4057 4058 # Alias the spins. 4059 spin70 = return_spin(":70") 4060 spin71 = return_spin(":71") 4061 4062 # The R20 keys. 4063 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4064 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4065 4066 # Set the initial parameter values. 4067 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4068 spin70.pA = 0.9 4069 spin70.dw = 6.0 4070 spin70.kex = 1500.0 4071 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4072 spin71.pA = 0.9 4073 spin71.dw = 4.0 4074 spin71.kex = 1900.0 4075 4076 # Low precision optimisation. 4077 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4078 4079 # Printout. 4080 print("\n\nOptimised parameters:\n") 4081 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4082 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4083 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4084 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4085 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4086 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4087 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4088 4089 # Checks for residue :70. 4090 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4091 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4092 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4093 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4094 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4095 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4096 4097 # Checks for residue :71. 4098 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4099 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4100 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4101 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4102 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4103 4104 # Test the conversion to k_AB from kex and pA. 4105 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4106 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4107 4108 # Test the conversion to k_BA from kex and pA. 4109 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4110 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4111 4112
4114 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4115 4116 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4117 """ 4118 4119 # Base data setup. 4120 self.setup_hansen_cpmg_data(model='CR72 full') 4121 4122 # Alias the spins. 4123 spin70 = return_spin(":70") 4124 spin71 = return_spin(":71") 4125 4126 # The R20 keys. 4127 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4128 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4129 4130 # Set the initial parameter values. 4131 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4132 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4133 spin70.pA = 0.9 4134 spin70.dw = 6.0 4135 spin70.kex = 1500.0 4136 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4137 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4138 spin71.pA = 0.9 4139 spin71.dw = 4.0 4140 spin71.kex = 1900.0 4141 4142 # Low precision optimisation. 4143 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4144 4145 # Printout. 4146 print("\n\nOptimised parameters:\n") 4147 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4148 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4149 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4150 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4151 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4152 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4153 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4154 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4155 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4156 4157 # Checks for residue :70. 4158 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4159 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4160 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4161 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4162 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4163 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4164 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4165 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4166 4167 # Checks for residue :71. 4168 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4169 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4170 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4171 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4172 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4173 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4174 4175 # Test the conversion to k_AB from kex and pA. 4176 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4177 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4178 4179 # Test the conversion to k_BA from kex and pA. 4180 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4181 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4182 4183
4185 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4186 4187 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4188 """ 4189 4190 # Base data setup. 4191 self.setup_hansen_cpmg_data(model='IT99') 4192 4193 # Alias the spins. 4194 spin70 = return_spin(":70") 4195 spin71 = return_spin(":71") 4196 4197 # The R20 keys. 4198 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4199 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4200 4201 # Set the initial parameter values. 4202 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4203 spin70.dw = 10.0 4204 spin70.pA = 0.5 4205 spin70.tex = 1000.09 4206 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4207 spin71.dw = 10.0 4208 spin71.pA = 0.95 4209 spin71.tex = 0.1 4210 4211 # Low precision optimisation. 4212 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4213 4214 # Printout. 4215 print("\n\nOptimised parameters:\n") 4216 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4217 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4218 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4219 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4220 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4221 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4222 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4223 4224 # Checks for residue :70. 4225 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4226 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4227 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4228 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4229 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4230 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4231 4232 # Checks for residue :71. 4233 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4234 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4235 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4236 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4237 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4238 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4239 4240
4242 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4243 4244 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4245 """ 4246 4247 # Base data setup. 4248 self.setup_hansen_cpmg_data(model='LM63') 4249 4250 # Alias the spins. 4251 spin70 = return_spin(":70") 4252 spin71 = return_spin(":71") 4253 4254 # The R20 keys. 4255 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4256 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4257 4258 # Set the initial parameter values. 4259 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4260 spin70.phi_ex = 0.3 4261 spin70.kex = 5000.0 4262 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4263 spin71.phi_ex = 0.1 4264 spin71.kex = 2500.0 4265 4266 # Low precision optimisation. 4267 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4268 4269 # Printout. 4270 print("\n\nOptimised parameters:\n") 4271 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4272 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4273 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4274 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4275 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4276 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4277 4278 # Checks for residue :70. 4279 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4280 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4281 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4282 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4283 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4284 4285 # Checks for residue :71. 4286 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4287 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4288 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4289 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4290 4291
4293 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4294 4295 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4296 """ 4297 4298 # Base data setup. 4299 self.setup_hansen_cpmg_data(model='LM63 3-site') 4300 4301 # Alias the spins. 4302 spin70 = return_spin(":70") 4303 spin71 = return_spin(":71") 4304 4305 # The R20 keys. 4306 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4307 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4308 4309 ## Set the initial parameter values. 4310 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4311 spin70.phi_ex_B = 0.14872003058250227 4312 spin70.phi_ex_C = 0.1319419923472704 4313 spin70.kB = 4103.672910444741 4314 spin70.kC = 7029.001690726248 4315 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4316 spin71.phi_ex_B = 0.04013553485505605 4317 spin71.phi_ex_C = 0.020050748406928887 4318 spin71.kB = 4045.3007136121364 4319 spin71.kC = 3586.38798270774 4320 4321 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4322 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4323 4324 # Low precision optimisation. 4325 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4326 4327 # Printout. 4328 print("\n\nOptimised parameters:\n") 4329 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4330 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4331 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4332 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4333 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4334 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4335 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4336 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4337 4338 # Checks for residue :70. 4339 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4340 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4341 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4342 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4343 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4344 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4345 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4346 4347 # Checks for residue :71. 4348 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4349 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4350 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4351 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4352 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4353 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4354 4355
4357 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4358 4359 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4360 """ 4361 4362 # Base data setup. 4363 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4364 4365 # Alias the spins. 4366 spin70 = return_spin(":70") 4367 spin71 = return_spin(":71") 4368 4369 # The R20 keys. 4370 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4371 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4372 4373 # Set the initial parameter values. 4374 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4375 spin70.pA = 0.9897754407 4376 spin70.dw = 5.642418428 4377 spin70.kex = 1743.666375 4378 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4379 spin71.pA = 0.9968032899 4380 spin71.dw = 4.577891393 4381 spin71.kex = 1830.044597 4382 4383 # Low precision optimisation. 4384 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4385 4386 # Printout. 4387 print("\n\nOptimised parameters:\n") 4388 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4389 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4390 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4391 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4392 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4393 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4394 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4395 4396 # Checks for residue :70. 4397 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4398 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4399 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4400 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4401 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4402 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4403 4404 # Checks for residue :71. 4405 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4406 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4407 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4408 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4409 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4410 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4411 4412 # Test the conversion to k_AB from kex and pA. 4413 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4414 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4415 4416 # Test the conversion to k_BA from kex and pA. 4417 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4418 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4419 4420
4422 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4423 4424 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4425 """ 4426 4427 # Base data setup. 4428 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4429 4430 # Alias the spins. 4431 spin70 = return_spin(":70") 4432 spin71 = return_spin(":71") 4433 4434 # The R20 keys. 4435 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4436 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4437 4438 # Set the initial parameter values. 4439 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4440 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4441 spin70.pA = 0.9884781357 4442 spin70.dw = 5.456507396 4443 spin70.kex = 1906.521189 4444 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4445 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4446 spin71.pA = 0.986709616684097 4447 spin71.dw = 2.09245158280905 4448 spin71.kex = 2438.2766211401 4449 4450 # Low precision optimisation. 4451 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4452 4453 # Printout. 4454 print("\n\nOptimised parameters:\n") 4455 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4456 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4457 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4458 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4459 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4460 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4461 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4462 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4463 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4464 4465 # Checks for residue :70. 4466 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4467 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4468 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4469 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4470 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4471 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4472 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4473 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4474 4475 # Checks for residue :71. 4476 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4477 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4478 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4479 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4480 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4481 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4482 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4483 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4484 4485 # Test the conversion to k_AB from kex and pA. 4486 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4487 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4488 4489 # Test the conversion to k_BA from kex and pA. 4490 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4491 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4492 4493
4495 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4496 4497 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4498 """ 4499 4500 # Base data setup. 4501 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4502 4503 # Alias the spins. 4504 spin70 = return_spin(":70") 4505 spin71 = return_spin(":71") 4506 4507 # The R20 keys. 4508 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4509 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4510 4511 # Set the initial parameter values. 4512 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4513 spin70.pA = 0.9 4514 spin70.dw = 6.0 4515 spin70.kex = 1500.0 4516 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4517 spin71.pA = 0.9 4518 spin71.dw = 4.0 4519 spin71.kex = 1900.0 4520 4521 # Low precision optimisation. 4522 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4523 4524 # Printout. 4525 print("\n\nOptimised parameters:\n") 4526 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4527 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4528 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4529 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4530 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4531 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4532 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4533 4534 # Checks for residue :70. 4535 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4536 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4537 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4538 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4539 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4540 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4541 4542 # Checks for residue :71. 4543 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4544 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4545 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4546 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4547 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4548 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4549 4550 # Test the conversion to k_AB from kex and pA. 4551 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4552 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4553 4554 # Test the conversion to k_BA from kex and pA. 4555 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4556 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4557 4558
4560 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4561 4562 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4563 """ 4564 4565 # Base data setup. 4566 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4567 4568 # Alias the spins. 4569 spin70 = return_spin(":70") 4570 spin71 = return_spin(":71") 4571 4572 # The R20 keys. 4573 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4574 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4575 4576 # Set the initial parameter values. 4577 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4578 spin70.pA = 0.9897519798 4579 spin70.dw = 5.644862195 4580 spin70.kex = 1723.820567 4581 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4582 spin71.pA = 0.9968032899 4583 spin71.dw = 4.577891393 4584 spin71.kex = 1830.044597 4585 4586 # Low precision optimisation. 4587 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4588 4589 # Printout. 4590 print("\n\nOptimised parameters:\n") 4591 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4592 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4593 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4594 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4595 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4596 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4597 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4598 4599 # Checks for residue :70. 4600 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4601 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4602 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4603 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4604 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4605 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4606 4607 # Checks for residue :71. 4608 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4609 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4610 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4611 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4612 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4613 4614 # Test the conversion to k_AB from kex and pA. 4615 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4616 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4617 4618 # Test the conversion to k_BA from kex and pA. 4619 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4620 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4621 4622
4624 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4625 4626 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4627 """ 4628 4629 # Base data setup. 4630 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4631 4632 # Alias the spins. 4633 spin70 = return_spin(":70") 4634 spin71 = return_spin(":71") 4635 4636 # The R20 keys. 4637 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4638 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4639 4640 # Set the initial parameter values. 4641 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4642 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4643 spin70.pA = 0.987648082613451 4644 spin70.dw = 5.30679853807572 4645 spin70.kex = 2033.25380420666 4646 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4647 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4648 spin71.pA = 0.992258541625787 4649 spin71.dw = 2.75140650899058 4650 spin71.kex = 2106.60885247431 4651 4652 # Low precision optimisation. 4653 self.interpreter.minimise.calculate() 4654 4655 # Checks for residue :70. 4656 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4657 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4658 4659
4660 - def test_hansen_cpmgfit_input(self):
4661 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4662 4663 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4664 """ 4665 4666 # Load the R2eff results file. 4667 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4668 self.interpreter.results.read(file_name) 4669 self.interpreter.deselect.spin(':4') 4670 4671 # Set up the model. 4672 self.interpreter.relax_disp.select_model('LM63') 4673 4674 # Generate the input files. 4675 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4676 4677 # What the files should contain. 4678 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4679 spin1 = [ 4680 "title :70@N\n", 4681 "fields 2 11.7432964915 18.7892743865\n", 4682 "function CPMG\n", 4683 "R2 1 10 20\n", 4684 "Rex 0 100.0 100\n", 4685 "Tau 0 10.0 100\n", 4686 "xmgr\n", 4687 "@ xaxis label \"1/tcp (1/ms)\"\n", 4688 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4689 "@ xaxis ticklabel format decimal\n", 4690 "@ yaxis ticklabel format decimal\n", 4691 "@ xaxis ticklabel char size 0.8\n", 4692 "@ yaxis ticklabel char size 0.8\n", 4693 "@ world xmin 0.0\n", 4694 "data\n", 4695 "0.133333 16.045541 0.310925 11.743296 \n", 4696 "0.266667 14.877925 0.303217 11.743296 \n", 4697 "0.400000 14.357820 0.299894 11.743296 \n", 4698 "0.533333 12.664495 0.289532 11.743296 \n", 4699 "0.666667 12.363205 0.287760 11.743296 \n", 4700 "0.800000 11.092532 0.280514 11.743296 \n", 4701 "0.933333 10.566090 0.277619 11.743296 \n", 4702 "1.066667 9.805807 0.273544 11.743296 \n", 4703 "1.200000 9.564301 0.272276 11.743296 \n", 4704 "1.333333 9.015634 0.269442 11.743296 \n", 4705 "1.466667 8.607765 0.267375 11.743296 \n", 4706 "1.600000 8.279997 0.265740 11.743296 \n", 4707 "1.733333 8.474536 0.266708 11.743296 \n", 4708 "1.866667 8.158973 0.265141 11.743296 \n", 4709 "2.000000 7.988631 0.264304 11.743296 \n", 4710 "0.133333 22.224914 0.166231 18.789274 \n", 4711 "0.266667 21.230874 0.162377 18.789274 \n", 4712 "0.400000 20.603704 0.160017 18.789274 \n", 4713 "0.533333 20.327797 0.158996 18.789274 \n", 4714 "0.666667 18.855377 0.153719 18.789274 \n", 4715 "0.800000 18.537531 0.152617 18.789274 \n", 4716 "0.933333 17.508069 0.149138 18.789274 \n", 4717 "1.066667 16.035604 0.144391 18.789274 \n", 4718 "1.200000 15.168192 0.141717 18.789274 \n", 4719 "1.333333 14.431802 0.139516 18.789274 \n", 4720 "1.466667 14.034137 0.138354 18.789274 \n", 4721 "1.600000 12.920148 0.135192 18.789274 \n", 4722 "1.733333 12.653673 0.134456 18.789274 \n", 4723 "1.866667 12.610864 0.134338 18.789274 \n", 4724 "2.000000 11.969303 0.132601 18.789274 \n" 4725 ] 4726 spin2 = [ 4727 "title :71@N\n", 4728 "fields 2 11.7432964915 18.7892743865\n", 4729 "function CPMG\n", 4730 "R2 1 10 20\n", 4731 "Rex 0 100.0 100\n", 4732 "Tau 0 10.0 100\n", 4733 "xmgr\n", 4734 "@ xaxis label \"1/tcp (1/ms)\"\n", 4735 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4736 "@ xaxis ticklabel format decimal\n", 4737 "@ yaxis ticklabel format decimal\n", 4738 "@ xaxis ticklabel char size 0.8\n", 4739 "@ yaxis ticklabel char size 0.8\n", 4740 "@ world xmin 0.0\n", 4741 "data\n", 4742 "0.133333 7.044342 0.170035 11.743296 \n", 4743 "0.266667 6.781033 0.169228 11.743296 \n", 4744 "0.400000 6.467623 0.168279 11.743296 \n", 4745 "0.533333 6.333340 0.167876 11.743296 \n", 4746 "0.666667 6.323238 0.167846 11.743296 \n", 4747 "0.800000 6.005245 0.166902 11.743296 \n", 4748 "0.933333 5.767052 0.166203 11.743296 \n", 4749 "1.066667 5.476968 0.165361 11.743296 \n", 4750 "1.200000 5.469949 0.165341 11.743296 \n", 4751 "1.333333 5.295113 0.164838 11.743296 \n", 4752 "1.466667 5.435648 0.165242 11.743296 \n", 4753 "1.600000 5.410400 0.165169 11.743296 \n", 4754 "1.733333 5.437554 0.165247 11.743296 \n", 4755 "1.866667 5.176844 0.164501 11.743296 \n", 4756 "2.000000 5.227232 0.164644 11.743296 \n", 4757 "0.133333 11.530903 0.081928 18.789274 \n", 4758 "0.266667 10.983094 0.081041 18.789274 \n", 4759 "0.400000 10.512403 0.080294 18.789274 \n", 4760 "0.533333 9.984805 0.079473 18.789274 \n", 4761 "0.666667 9.573163 0.078845 18.789274 \n", 4762 "0.800000 9.178810 0.078253 18.789274 \n", 4763 "0.933333 8.935719 0.077893 18.789274 \n", 4764 "1.066667 8.610147 0.077416 18.789274 \n", 4765 "1.200000 8.353778 0.077045 18.789274 \n", 4766 "1.333333 8.173729 0.076787 18.789274 \n", 4767 "1.466667 8.091607 0.076670 18.789274 \n", 4768 "1.600000 7.706420 0.076126 18.789274 \n", 4769 "1.733333 7.709125 0.076129 18.789274 \n", 4770 "1.866667 7.610856 0.075992 18.789274 \n", 4771 "2.000000 7.552584 0.075911 18.789274 \n", 4772 ] 4773 4774 # Check the batch file. 4775 print("\nChecking the batch file.") 4776 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 4777 lines = file.readlines() 4778 file.close() 4779 for i in range(len(lines)): 4780 self.assertEqual(batch_file[i], lines[i]) 4781 4782 # Check spin :70@N. 4783 print("\nChecking the spin :70@N input file.") 4784 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 4785 lines = file.readlines() 4786 file.close() 4787 for i in range(len(spin1)): 4788 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4789 for i in range(len(lines)): 4790 self.assertEqual(spin1[i], lines[i]) 4791 4792 # Check spin :71@N. 4793 print("\nChecking the spin :71@N input file.") 4794 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 4795 lines = file.readlines() 4796 file.close() 4797 for i in range(len(lines)): 4798 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4799 for i in range(len(spin2)): 4800 self.assertEqual(spin2[i], lines[i])
4801 4802
4804 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 4805 4806 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4807 4808 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 4809 4810 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 4811 - pA = 0.965402506690231, 4812 - dw = 0.805197170133360, 4813 - dwH = -0.595536627771890, 4814 - kex = 569.003663067619868, 4815 - chi2 = 9.297671357952812. 4816 """ 4817 4818 # Base data setup. 4819 self.setup_korzhnev_2005_data(data_list=['DQ']) 4820 4821 # Alias the spin. 4822 spin = return_spin(":9@N") 4823 4824 # The R20 keys. 4825 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 4826 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 4827 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 4828 4829 # Set the initial parameter values. 4830 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 4831 spin.pA = 0.965638501551899 4832 spin.dw = 2.8537583461577 4833 spin.dwH = -0.387633062766635 4834 spin.kex = 573.704033851592 4835 4836 # Low precision optimisation. 4837 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4838 4839 # Monte Carlo simulations. 4840 self.interpreter.monte_carlo.setup(number=2) 4841 self.interpreter.monte_carlo.create_data(method='back_calc') 4842 self.interpreter.monte_carlo.initial_values() 4843 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4844 self.interpreter.monte_carlo.error_analysis() 4845 4846 # Plot the dispersion curves. 4847 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4848 4849 # Save the results. 4850 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4851 4852 # Printout. 4853 print("\n\nOptimised parameters:\n") 4854 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4855 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4856 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4857 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4858 print("%-20s %20.15g" % ("pA", spin.pA)) 4859 print("%-20s %20.15g" % ("dw", spin.dw)) 4860 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4861 print("%-20s %20.15g" % ("kex", spin.kex)) 4862 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4863 4864 # Checks for residue :9. 4865 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 4866 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 4867 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 4868 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 4869 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 4870 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 4871 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 4872 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
4873 4874
4876 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 4877 4878 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4879 4880 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 4881 4882 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 4883 - pA = 0.930027999814003, 4884 - dw = 4.338620619954370, 4885 - dwH = -0.274250775560818, 4886 - kex = 344.613362916544475, 4887 - chi2 = 10.367733168217050. 4888 """ 4889 4890 # Base data setup. 4891 self.setup_korzhnev_2005_data(data_list=['MQ']) 4892 4893 # Alias the spin. 4894 spin = return_spin(":9@N") 4895 4896 # The R20 keys. 4897 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 4898 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 4899 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 4900 4901 # Set the initial parameter values. 4902 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 4903 spin.pA = 0.930083249288083 4904 spin.dw = 4.33890689462363 4905 spin.dwH = -0.274316585638047 4906 spin.kex = 344.329651956132 4907 4908 # Low precision optimisation. 4909 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4910 4911 # Monte Carlo simulations. 4912 self.interpreter.monte_carlo.setup(number=2) 4913 self.interpreter.monte_carlo.create_data(method='back_calc') 4914 self.interpreter.monte_carlo.initial_values() 4915 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4916 self.interpreter.monte_carlo.error_analysis() 4917 4918 # Plot the dispersion curves. 4919 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4920 4921 # Save the results. 4922 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4923 4924 # Printout. 4925 print("\n\nOptimised parameters:\n") 4926 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4927 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4928 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4929 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4930 print("%-20s %20.15g" % ("pA", spin.pA)) 4931 print("%-20s %20.15g" % ("dw", spin.dw)) 4932 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4933 print("%-20s %20.15g" % ("kex", spin.kex)) 4934 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4935 4936 # Checks for residue :9. 4937 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 4938 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 4939 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 4940 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 4941 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 4942 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 4943 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 4944 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
4945 4946
4948 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 4949 4950 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4951 4952 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 4953 4954 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 4955 - pA = 0.950003458294991, 4956 - dw = 4.358402855315123, 4957 - kex = 429.906473361926999, 4958 - chi2 = 17.393331915567252. 4959 """ 4960 4961 # Base data setup. 4962 self.setup_korzhnev_2005_data(data_list=['SQ']) 4963 4964 # Alias the spin. 4965 spin = return_spin(":9@N") 4966 4967 # The R20 keys. 4968 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4969 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 4970 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4971 4972 # Set the initial parameter values. 4973 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 4974 spin.pA = 0.950310172115387 4975 spin.dw = 4.356737157889636 4976 spin.kex = 433.176323890829849 4977 4978 # Low precision optimisation. 4979 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4980 4981 # Monte Carlo simulations. 4982 self.interpreter.monte_carlo.setup(number=2) 4983 self.interpreter.monte_carlo.create_data(method='back_calc') 4984 self.interpreter.monte_carlo.initial_values() 4985 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4986 self.interpreter.monte_carlo.error_analysis() 4987 4988 # Plot the dispersion curves. 4989 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4990 4991 # Save the results. 4992 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4993 4994 # Printout. 4995 print("\n\nOptimised parameters:\n") 4996 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4997 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4998 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4999 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5000 print("%-20s %20.15g" % ("pA", spin.pA)) 5001 print("%-20s %20.15g" % ("dw", spin.dw)) 5002 print("%-20s %20.15g" % ("kex", spin.kex)) 5003 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5004 5005 # Checks for residue :9. 5006 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5007 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5008 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5009 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5010 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5011 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5012 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5013 5014
5016 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5017 5018 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5019 5020 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5021 5022 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5023 - pA = 0.942452612380140, 5024 - dw = 0.858972784230892, 5025 - dwH = 0.087155962730608, 5026 - kex = 373.219151384798920, 5027 - chi2 = 23.863208106025152. 5028 """ 5029 5030 # Base data setup. 5031 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5032 5033 # Alias the spin. 5034 spin = return_spin(":9@N") 5035 5036 # The R20 keys. 5037 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5038 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5039 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5040 5041 # Set the initial parameter values. 5042 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5043 spin.pA = 0.942457332074014 5044 spin.dw = 0.850592422908884 5045 spin.dwH = 0.0881272284455416 5046 spin.kex = 372.745483351305 5047 5048 # Low precision optimisation. 5049 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5050 5051 # Monte Carlo simulations. 5052 self.interpreter.monte_carlo.setup(number=2) 5053 self.interpreter.monte_carlo.create_data(method='back_calc') 5054 self.interpreter.monte_carlo.initial_values() 5055 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5056 self.interpreter.monte_carlo.error_analysis() 5057 5058 # Plot the dispersion curves. 5059 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5060 5061 # Save the results. 5062 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5063 5064 # Printout. 5065 print("\n\nOptimised parameters:\n") 5066 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5067 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5068 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5069 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5070 print("%-20s %20.15g" % ("pA", spin.pA)) 5071 print("%-20s %20.15g" % ("dw", spin.dw)) 5072 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5073 print("%-20s %20.15g" % ("kex", spin.kex)) 5074 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5075 5076 # Checks for residue :9. 5077 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5078 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5079 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5080 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5081 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5082 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5083 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5084 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5085 5086
5088 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5089 5090 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5091 5092 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5093 5094 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5095 - pA = 0.936911090448340, 5096 - dw = 4.325314846914845, 5097 - dwH = -0.213870168665628, 5098 - kex = 487.361914835074117, 5099 - chi2 = 14.870371897291138. 5100 """ 5101 5102 # Base data setup. 5103 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5104 5105 # Alias the spin. 5106 spin = return_spin(":9@N") 5107 5108 # The R20 keys. 5109 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5110 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5111 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5112 5113 # Set the initial parameter values. 5114 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5115 spin.pA = 0.936884348941701 5116 spin.dw = 4.326454531583964 5117 spin.dwH = -0.214026093221782 5118 spin.kex = 487.043592705469223 5119 5120 # Low precision optimisation. 5121 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5122 5123 # Monte Carlo simulations. 5124 self.interpreter.monte_carlo.setup(number=2) 5125 self.interpreter.monte_carlo.create_data(method='back_calc') 5126 self.interpreter.monte_carlo.initial_values() 5127 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5128 self.interpreter.monte_carlo.error_analysis() 5129 5130 # Plot the dispersion curves. 5131 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5132 5133 # Save the results. 5134 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5135 5136 # Printout. 5137 print("\n\nOptimised parameters:\n") 5138 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5139 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5140 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5141 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5142 print("%-20s %20.15g" % ("pA", spin.pA)) 5143 print("%-20s %20.15g" % ("dw", spin.dw)) 5144 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5145 print("%-20s %20.15g" % ("kex", spin.kex)) 5146 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5147 5148 # Checks for residue :9. 5149 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5150 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5151 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5152 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5153 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5154 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5155 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5156 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5157 5158
5160 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5161 5162 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5163 5164 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5165 5166 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5167 - pA = 0.946949480545876, 5168 - dwH = -0.265279672133308, 5169 - kex = 406.548178869750700, 5170 - chi2 = 50.400680290545026. 5171 """ 5172 5173 # Base data setup. 5174 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5175 5176 # Alias the spin. 5177 spin = return_spin(":9@N") 5178 5179 # The R20 keys. 5180 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5181 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5182 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5183 5184 # Set the initial parameter values. 5185 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5186 spin.pA = 0.946990967372467 5187 spin.dwH = -0.265308128403529 5188 spin.kex = 406.843250675648 5189 5190 # Low precision optimisation. 5191 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5192 5193 # Monte Carlo simulations. 5194 self.interpreter.monte_carlo.setup(number=2) 5195 self.interpreter.monte_carlo.create_data(method='back_calc') 5196 self.interpreter.monte_carlo.initial_values() 5197 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5198 self.interpreter.monte_carlo.error_analysis() 5199 5200 # Plot the dispersion curves. 5201 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5202 5203 # Save the results. 5204 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5205 5206 # Printout. 5207 print("\n\nOptimised parameters:\n") 5208 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5209 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5210 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5211 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5212 print("%-20s %20.15g" % ("pA", spin.pA)) 5213 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5214 print("%-20s %20.15g" % ("kex", spin.kex)) 5215 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5216 5217 # Checks for residue :9. 5218 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5219 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5220 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5221 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5222 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5223 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5224 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5225 5226
5228 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5229 5230 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5231 5232 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5233 5234 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5235 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5236 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5237 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5238 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5239 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5240 - pA = 0.943125351763911, 5241 - dw = 4.421827493809807, 5242 - dwH = -0.272637034755752, 5243 - kex = 360.609744568697238, 5244 - chi2 = 162.589570340050813. 5245 """ 5246 5247 # Base data setup. 5248 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5249 5250 # Alias the spin. 5251 spin = return_spin(":9@N") 5252 5253 # The R20 keys. 5254 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5255 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5256 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5257 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5258 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5259 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5260 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5261 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5262 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5263 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5264 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5265 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5266 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5267 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5268 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5269 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5270 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5271 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5272 5273 # Set the initial parameter values. 5274 spin.r2 = { 5275 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5276 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5277 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5278 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5279 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5280 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5281 } 5282 spin.pA = 0.943129019477673 5283 spin.dw = 4.42209952545181 5284 spin.dwH = -0.27258970590969 5285 spin.kex = 360.516132791038 5286 5287 # Low precision optimisation. 5288 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5289 5290 # Monte Carlo simulations. 5291 self.interpreter.monte_carlo.setup(number=2) 5292 self.interpreter.monte_carlo.create_data(method='back_calc') 5293 self.interpreter.monte_carlo.initial_values() 5294 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5295 self.interpreter.monte_carlo.error_analysis() 5296 5297 # Plot the dispersion curves. 5298 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5299 5300 # Save the results. 5301 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5302 5303 # Printout. 5304 print("\n\nOptimised parameters:\n") 5305 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5306 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5307 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5308 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5309 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5310 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5311 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5312 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5313 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5314 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5315 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5316 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5317 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5318 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5319 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5320 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5321 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5322 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5323 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5324 print("%-20s %20.15g" % ("pA", spin.pA)) 5325 print("%-20s %20.15g" % ("dw", spin.dw)) 5326 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5327 print("%-20s %20.15g" % ("kex", spin.kex)) 5328 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5329 5330 # Checks for residue :9. 5331 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5332 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5333 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5334 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5335 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5336 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5337 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5338 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5339 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5340 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5341 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5342 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5343 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5344 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5345 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5346 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5347 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5348 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5349 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5350 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5351 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5352 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5353 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5354 5355
5357 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5358 5359 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5360 5361 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5362 5363 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5364 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5365 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5366 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5367 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5368 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5369 - pA = 0.943125351763911, 5370 - dw = 4.421827493809807, 5371 - dwH = -0.272637034755752, 5372 - kex = 360.609744568697238, 5373 - chi2 = 162.589570340050813. 5374 """ 5375 5376 # Base data setup. 5377 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5378 5379 # Alias the spin. 5380 spin = return_spin(":9@N") 5381 5382 # The R20 keys. 5383 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5384 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5385 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5386 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5387 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5388 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5389 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5390 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5391 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5392 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5393 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5394 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5395 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5396 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5397 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5398 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5399 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5400 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5401 5402 # Set the initial parameter values. 5403 spin.r2 = { 5404 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5405 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5406 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5407 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5408 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5409 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5410 } 5411 spin.pA = 0.943129019477673 5412 spin.dw = 4.42209952545181 5413 spin.dwH = -0.27258970590969 5414 spin.kex = 360.516132791038 5415 5416 # Calc the chi2 values at these parameters. 5417 self.interpreter.minimise.calculate(verbosity=1) 5418 5419 # Printout. 5420 print("\n\nOptimised parameters:\n") 5421 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5422 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5423 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5424 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5425 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5426 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5427 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5428 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5429 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5430 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5431 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5432 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5433 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5434 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5435 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5436 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5437 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5438 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5439 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5440 print("%-20s %20.15g" % ("pA", spin.pA)) 5441 print("%-20s %20.15g" % ("dw", spin.dw)) 5442 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5443 print("%-20s %20.15g" % ("kex", spin.kex)) 5444 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5445 5446 # Checks for residue :9. 5447 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5448 5449
5451 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5452 5453 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5454 5455 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5456 5457 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5458 - 0.483 0.89623903 2.4503699912708878 5459 - 0.545 1.1694838 5460 - 0.545 1.1761503 5461 - 0.622 1.294 5462 - 0.669 1.5176493 5463 - 0.722 1.6238791 5464 - 0.813 1.9395758 5465 - 1.011 2.3558415 10.547000429321157 5466 """ 5467 5468 # Base data setup. 5469 model = 'TSMFK01' 5470 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5471 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5472 5473 # Alias the spins. 5474 res61L = cdp.mol[0].res[0].spin[0] 5475 5476 # The R20 keys. 5477 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5478 5479 # Set the initial parameter values. 5480 res61L.r2a = {r20_key1: 8.0} 5481 res61L.dw = 6.5 5482 res61L.k_AB = 2.5 5483 5484 # Low precision optimisation. 5485 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5486 5487 # Start testing all possible combinations of graphs. 5488 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5489 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5490 interpolate_types = [INTERPOLATE_DISP] 5491 5492 # Write to temp folder. 5493 result_dir_name = ds.tmpdir 5494 result_folders = [model] 5495 spin_id = ":61@N" 5496 5497 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5498 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5499 5500 for result_folder in result_folders: 5501 for y_axis in y_axis_types: 5502 for x_axis in x_axis_types: 5503 for interpolate in interpolate_types: 5504 # Determine file name: 5505 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5506 5507 # Make the file name. 5508 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5509 5510 # Write the curves. 5511 dir = result_dir_name+sep+result_folder 5512 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5513 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5514 5515 # Get the file path. 5516 file_path = get_file_path(file_name, dir) 5517 5518 # Test the plot file exists. 5519 print("Testing file access to graph: %s"%file_path) 5520 self.assert_(access(file_path, F_OK)) 5521 5522 # Now open, and compare content, line by line. 5523 file_prod = open(file_path) 5524 lines_prod = file_prod.readlines() 5525 file_prod.close() 5526 5527 # Define file to compare against. 5528 dir_comp = data_path+sep+result_folder 5529 file_path_comp = get_file_path(file_name, dir_comp) 5530 file_comp = open(file_path_comp) 5531 lines_comp = file_comp.readlines() 5532 file_comp.close() 5533 5534 ## Assert number of lines is equal. 5535 self.assertEqual(len(lines_prod), len(lines_comp)) 5536 for j in range(len(lines_prod)): 5537 # Make the string test 5538 first_char = lines_prod[j][0] 5539 if first_char in ["@", "&"]: 5540 self.assertEqual(lines_prod[j], lines_comp[j]) 5541 else: 5542 # Split string in x, y, error. 5543 # The error would change per run. 5544 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5545 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5546 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5547 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5548 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5549 5550
5552 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5553 5554 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5555 """ 5556 5557 # Base data setup. 5558 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5559 5560 # Alias the spins. 5561 res61L = cdp.mol[0].res[0].spin[0] 5562 5563 # The R20 keys. 5564 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5565 5566 # Set the initial parameter values. 5567 res61L.r2 = {r20_key1: 8.0} 5568 res61L.pA = 0.9 5569 res61L.dw = 6.0 5570 res61L.kex = 600.0 5571 5572 # Low precision optimisation. 5573 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5574 5575 # Printout. 5576 print("\n\nOptimised parameters:\n") 5577 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5578 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5579 print("%-20s %20.15g" % ("pA", res61L.pA)) 5580 print("%-20s %20.15g" % ("dw", res61L.dw)) 5581 print("%-20s %20.15g" % ("kex", res61L.kex)) 5582 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5583 5584 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5585 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5586 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5587 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5588 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5589 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5590 5591 # Test the conversion to k_AB from kex and pA. 5592 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5593 5594 # Test the conversion to k_BA from kex and pA. 5595 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5596 5597
5599 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5600 5601 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5602 """ 5603 5604 # Base data setup. 5605 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5606 5607 # Alias the spins. 5608 res61L = cdp.mol[0].res[0].spin[0] 5609 5610 # The R20 keys. 5611 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5612 5613 # Set the initial parameter values. 5614 res61L.r2a = {r20_key1: 8.0} 5615 res61L.r2b = {r20_key1: 105.0} 5616 res61L.pA = 0.9 5617 res61L.dw = 6.0 5618 res61L.kex = 500.0 5619 5620 # Low precision optimisation. 5621 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5622 5623 # Printout. 5624 print("\n\nOptimised parameters:\n") 5625 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5626 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5627 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5628 print("%-20s %20.15g" % ("pA", res61L.pA)) 5629 print("%-20s %20.15g" % ("dw", res61L.dw)) 5630 print("%-20s %20.15g" % ("kex", res61L.kex)) 5631 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5632 5633 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5634 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5635 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5636 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5637 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5638 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5639 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5640 5641
5643 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5644 5645 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5646 5647 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5648 5649 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5650 - 0.483 0.89623903 2.4503699912708878 5651 - 0.545 1.1694838 5652 - 0.545 1.1761503 5653 - 0.622 1.294 5654 - 0.669 1.5176493 5655 - 0.722 1.6238791 5656 - 0.813 1.9395758 5657 - 1.011 2.3558415 10.547000429321157 5658 """ 5659 5660 # Base data setup. 5661 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5662 5663 # Alias the spins. 5664 res61L = cdp.mol[0].res[0].spin[0] 5665 5666 # The R20 keys. 5667 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5668 5669 # Set the initial parameter values. 5670 res61L.r2a = {r20_key1: 8.0} 5671 res61L.dw = 6.5 5672 res61L.k_AB = 2.5 5673 5674 # Low precision optimisation. 5675 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5676 5677 # Printout. 5678 print("\n\nOptimised parameters:\n") 5679 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5680 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5681 print("%-20s %20.15g" % ("dw", res61L.dw)) 5682 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5683 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5684 5685 # Checks for residue :61. Reference values from paper 5686 5687 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5688 5689
5691 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5692 5693 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5694 5695 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5696 5697 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5698 5699 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5700 - k_AB = 11.3 +/- 0.7 s^-1, 5701 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5702 - R2 = 8.0 +/- 0.5 s^-1. 5703 5704 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5705 - k_AB = 10.55 +/- 0.08 s^-1, 5706 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5707 - R2 = 8.4 +/- 0.3 s^-1. 5708 5709 Conversion of paper results to relax results is performed by: 5710 5711 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5712 5713 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5714 5715 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5716 - 0.483 0.89623903 2.4503699912708878 5717 - 0.545 1.1694838 5718 - 0.545 1.1761503 5719 - 0.622 1.294 5720 - 0.669 1.5176493 5721 - 0.722 1.6238791 5722 - 0.813 1.9395758 5723 - 1.011 2.3558415 10.547000429321157 5724 """ 5725 5726 # Base data setup. 5727 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5728 5729 # Alias the spins. 5730 res61L = cdp.mol[0].res[0].spin[0] 5731 5732 # The R20 keys. 5733 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5734 5735 # Set the initial parameter values. 5736 res61L.r2a = {r20_key1: 8.0} 5737 res61L.dw = 6.5 5738 res61L.k_AB = 11.0 5739 5740 # Low precision optimisation. 5741 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5742 5743 # Printout. 5744 print("\n\nOptimised parameters:\n") 5745 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5746 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5747 print("%-20s %20.15g" % ("dw", res61L.dw)) 5748 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5749 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5750 5751 # Checks for residue :61. Reference values from paper 5752 5753 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 5754 self.assertAlmostEqual(res61L.dw, 6.41, 0) 5755 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5756 5757
5758 - def test_lm63_3site_synthetic(self):
5759 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 5760 5761 # The path to the data files. 5762 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 5763 5764 # Load the state file. 5765 self.interpreter.reset() 5766 self.interpreter.state.load(data_path+sep+'r2eff_values') 5767 5768 # A new data pipe. 5769 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 5770 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 5771 5772 # Set up the model data. 5773 self.interpreter.relax_disp.select_model(model='LM63 3-site') 5774 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 5775 self.interpreter.spin.isotope('15N') 5776 5777 # Alias the spins. 5778 spin1 = return_spin(":1") 5779 spin2 = return_spin(":2") 5780 5781 # The R20 keys. 5782 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5783 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5784 5785 # Manually set the parameter values. 5786 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 5787 spin1.phi_ex_B = 0.1 5788 spin1.phi_ex_C = 0.5 5789 spin1.kB = 1500.0 5790 spin1.kC = 2500.0 5791 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 5792 spin2.phi_ex_B = 0.1 5793 spin2.phi_ex_C = 0.5 5794 spin2.kB = 1500.0 5795 spin2.kC = 2500.0 5796 5797 # Low precision optimisation. 5798 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5799 5800 # Monte Carlo simulations. 5801 self.interpreter.monte_carlo.setup(number=3) 5802 self.interpreter.monte_carlo.create_data(method='back_calc') 5803 self.interpreter.monte_carlo.initial_values() 5804 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 5805 self.interpreter.monte_carlo.error_analysis() 5806 5807 # Save the results. 5808 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 5809 5810 # The model checks. 5811 print("\n\nOptimised parameters:\n") 5812 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 5813 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 5814 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 5815 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 5816 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 5817 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 5818 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 5819 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 5820 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 5821 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 5822 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5823 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5824 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5825 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5826 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 5827 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 5828 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 5829 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5830 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5831 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5832 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5833 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
5834 5835
5836 - def test_m61_data_to_m61(self):
5837 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 5838 5839 # Fixed time variable. 5840 ds.fixed = True 5841 5842 # Execute the script. 5843 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 5844 5845 # The original parameters. 5846 i0 = [100000.0, 20000.0] 5847 r1rho_prime = [2.25, 24.0] 5848 pA = 0.7 5849 kex = 1000.0 5850 delta_omega = [1.0, 2.0] 5851 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 5852 phi_ex = [] 5853 for i in range(2): 5854 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 5855 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 5856 5857 # Switch to the 'R2eff' model data pipe, then check for each spin. 5858 self.interpreter.pipe.switch('R2eff - relax_disp') 5859 spin_index = 0 5860 for spin, spin_id in spin_loop(return_id=True): 5861 # Printout. 5862 print("\nSpin %s." % spin_id) 5863 5864 # Check the fitted parameters. 5865 for i in range(len(keys)): 5866 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 5867 5868 # Increment the spin index. 5869 spin_index += 1 5870 5871 # The R20 keys. 5872 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5873 5874 # Switch to the 'M61' model data pipe, then check for each spin. 5875 self.interpreter.pipe.switch('M61 - relax_disp') 5876 spin_index = 0 5877 for spin, spin_id in spin_loop(return_id=True): 5878 # Printout. 5879 print("\nSpin %s." % spin_id) 5880 5881 # Check the fitted parameters. 5882 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5883 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 5884 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5885 5886 # Increment the spin index. 5887 spin_index += 1
5888 5889
5890 - def test_m61_exp_data_to_m61(self):
5891 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 5892 5893 # Fixed time variable. 5894 ds.fixed = False 5895 5896 # Single spin optimisation. 5897 ds.single = True 5898 5899 # Execute the script. 5900 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 5901 5902 # The original parameters. 5903 i0 = [100000.0, 20000.0] 5904 r1rho_prime = [2.25, 24.0] 5905 pA = 0.7 5906 kex = 1000.0 5907 delta_omega = [1.0, 2.0] 5908 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 5909 phi_ex = [] 5910 for i in range(2): 5911 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 5912 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 5913 5914 # Switch to the 'R2eff' model data pipe, then check for each spin. 5915 self.interpreter.pipe.switch('R2eff - relax_disp') 5916 spin_index = 0 5917 for spin, spin_id in spin_loop(return_id=True): 5918 # Printout. 5919 print("\nSpin %s." % spin_id) 5920 5921 # Check the fitted parameters. 5922 for i in range(len(keys)): 5923 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 5924 5925 # Increment the spin index. 5926 spin_index += 1 5927 5928 # The R20 keys. 5929 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5930 5931 # Switch to the 'M61' model data pipe, then check for each spin. 5932 self.interpreter.pipe.switch('M61 - relax_disp') 5933 spin_index = 0 5934 for spin, spin_id in spin_loop(return_id=True): 5935 # Printout. 5936 print("\nSpin %s." % spin_id) 5937 5938 # Check the fitted parameters. 5939 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5940 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 5941 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5942 5943 # Increment the spin index. 5944 spin_index += 1
5945 5946
5947 - def test_m61b_data_to_m61b(self):
5948 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 5949 5950 # Execute the script. 5951 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 5952 5953 # The original parameters. 5954 i0 = [100000.0, 20000.0] 5955 r1rho_prime = [10.0, 24.0] 5956 pA = 0.95 5957 kex = 2000.0 5958 delta_omega = [1.0, 2.0] 5959 5960 # The R20 keys. 5961 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5962 5963 # Switch to the 'M61 skew' model data pipe, then check for each spin. 5964 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 5965 spin_index = 0 5966 for spin, spin_id in spin_loop(return_id=True): 5967 # Printout. 5968 print("\nSpin %s." % spin_id) 5969 5970 # Check the fitted parameters. 5971 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5972 self.assertAlmostEqual(spin.pA, pA, 2) 5973 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 5974 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5975 5976 # Increment the spin index. 5977 spin_index += 1
5978 5979
5981 """Test that all models which can nest, have all their parameters converted.""" 5982 5983 # Set the experiment type. 5984 cdp.exp_type_list = EXP_TYPE_LIST 5985 5986 # Get info for all models. 5987 all_models_info = models_info(models=MODEL_LIST_FULL) 5988 5989 # Loop over all models. 5990 print("Printing the listed of nested models for each model.") 5991 print("#########################################") 5992 for model_info in all_models_info: 5993 print("%s"%model_info.model), 5994 print("<-"), 5995 nest_list = model_info.nest_list 5996 if nest_list == None: 5997 nest_list = ["None"] 5998 print(', '.join(map(str, nest_list))) 5999 6000 # Skip if there is no model to nest from. 6001 if nest_list == ["None"]: 6002 continue 6003 6004 # Assign params to variable. 6005 model_params = model_info.params 6006 6007 # Now loop over the nested models. 6008 for nested_model in nest_list: 6009 # Get the params for the nested model. 6010 nested_model_params = MODEL_PARAMS[nested_model] 6011 6012 # Get the dictionary of parameter conversion. 6013 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6014 6015 # Test the number of elements in the dictionary. 6016 self.assertEqual(len(par_dic), len(model_params)) 6017 6018 # Loop over dictionary. 6019 for param, param_conv in par_dic.iteritems(): 6020 if param != param_conv: 6021 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, param_conv, param)) 6022 self.assertNotEqual(param_conv, None)
6023 6024
6025 - def test_ns_mmq_3site(self):
6026 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6027 6028 # Execute the script. 6029 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6030 6031 # Check the chi-squared value. 6032 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6033 6034
6035 - def test_ns_mmq_3site_linear(self):
6036 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6037 6038 # Execute the script. 6039 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6040 6041 # Check the chi-squared value. 6042 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6043 6044
6045 - def test_ns_r1rho_3site(self):
6046 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6047 6048 # Execute the script. 6049 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6050 6051 # Check the chi-squared value. 6052 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6053 6054
6055 - def test_ns_r1rho_3site_linear(self):
6056 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6057 6058 # Execute the script. 6059 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6060 6061 # Check the chi-squared value. 6062 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6063 6064
6065 - def test_repeat_cpmg(self):
6066 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6067 6068 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6069 """ 6070 6071 # Reset. 6072 self.interpreter.reset() 6073 6074 # Define base path to files. 6075 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6076 6077 # Setup dictionary with settings. 6078 sdic = {} 6079 6080 # Spectrometer frqs in list. 6081 sfrq_1 = 499.86214 6082 sfrq_2 = 599.8908587 6083 sfrqs = [sfrq_1, sfrq_2] 6084 6085 # Store in dictionary. 6086 sdic['sfrqs'] = sfrqs 6087 6088 # Store unit for frq. 6089 sdic['sfrq_unit'] = 'MHz' 6090 6091 # Store exp_type 6092 sdic['exp_type'] = 'SQ CPMG' 6093 6094 # Store spin isotope 6095 sdic['isotope'] = '15N' 6096 6097 # How intensity was measured. 6098 sdic['int_method'] = 'height' 6099 6100 # Define the time for result directory. 6101 sdic['time'] = '2014_09' 6102 6103 # Initialize frq dics. 6104 for frq in sfrqs: 6105 key = DIC_KEY_FORMAT % (frq) 6106 sdic[key] = {} 6107 6108 # Set keys. 6109 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6110 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6111 6112 # Store time T2. 6113 sdic[e_1]['time_T2'] = 0.04 6114 sdic[e_2]['time_T2'] = 0.06 6115 6116 # Set ncyc. 6117 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6118 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6119 6120 # Calculate the cpmg_frq and store. 6121 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6122 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6123 6124 # Define peak lists. 6125 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6126 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6127 sdic[e_1]['peaks_folder'] = peaks_folder_1 6128 sdic[e_2]['peaks_folder'] = peaks_folder_2 6129 6130 # Define folder to all rmsd files. 6131 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6132 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6133 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6134 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6135 6136 # Define temporary folder. 6137 sdic['results_dir'] = self.tmpdir 6138 6139 # Setup class with data. 6140 RDR = Relax_disp_rep(sdic) 6141 6142 # Setup base information. 6143 RDR.set_base_cpmg(method='FT', glob_ini=128) 6144 6145 methods = ['FT', 'MDD'] 6146 #methods = ['FT'] 6147 6148 # Set the intensity. 6149 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6150 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6151 6152 # Try plot some intensity correlations. 6153 if True: 6154 selection = None 6155 6156 # Now make a spin selection. 6157 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6158 6159 # For mdd 6160 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6161 6162 # Plot correlation of intensity 6163 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6164 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6165 corr_data = [fig1, fig2] 6166 6167 write_stats = True 6168 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6169 6170 # Open stat file. 6171 if write_stats: 6172 for i, corr_data_i in enumerate(corr_data): 6173 data, methods, glob_inis = corr_data[i] 6174 data_x, data_y = data 6175 method_x, method_y = methods 6176 glob_ini_x, glob_ini_y = glob_inis 6177 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6178 np = len(x) 6179 6180 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6181 6182 if selection == None: 6183 file_name = file_name_ini + '_all.txt' 6184 else: 6185 file_name = file_name_ini + '_sel.txt' 6186 path = RDR.results_dir 6187 data = extract_data(file=file_name, dir=path) 6188 6189 # Loop over the lines. 6190 for i, data_i in enumerate(data): 6191 print(i, data_i) 6192 6193 6194 # Try plot some intensity statistics. 6195 if True: 6196 # Collect r2eff values. 6197 selections = [None, ':2,3'] 6198 for selection in selections: 6199 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6200 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6201 6202 # Get R2eff stats. 6203 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6204 6205 ## Plot R2eff stats 6206 write_stats = True 6207 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6208 6209 # Open stat file. 6210 if write_stats: 6211 if selection == None: 6212 file_name = 'int_stat_all.txt' 6213 else: 6214 file_name = 'int_stat_sel.txt' 6215 path = RDR.results_dir 6216 data = extract_data(file=file_name, dir=path) 6217 6218 # Loop over the lines. 6219 for i, data_i in enumerate(data): 6220 print(i, data_i) 6221 6222 6223 # Try write some R2eff correlations. 6224 if True: 6225 selection = None 6226 # Collect r2eff values. 6227 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6228 6229 # For all spins, mdd 6230 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6231 6232 # Plot correlation of intensity 6233 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6234 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6235 corr_data = [fig1, fig2] 6236 6237 write_stats = True 6238 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6239 6240 # Open stat file. 6241 if write_stats: 6242 for i, corr_data_i in enumerate(corr_data): 6243 data, methods, glob_inis = corr_data[i] 6244 data_x, data_y = data 6245 method_x, method_y = methods 6246 glob_ini_x, glob_ini_y = glob_inis 6247 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6248 np = len(x) 6249 6250 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6251 6252 if selection == None: 6253 file_name = file_name_ini + '_all.txt' 6254 else: 6255 file_name = file_name_ini + '_sel.txt' 6256 path = RDR.results_dir 6257 data = extract_data(file=file_name, dir=path) 6258 6259 # Loop over the lines. 6260 for i, data_i in enumerate(data): 6261 print(i, data_i) 6262 6263 6264 # Try plot some R2eff statistics. 6265 if True: 6266 # Collect r2eff values. 6267 selections = [None, ':2,3'] 6268 for selection in selections: 6269 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6270 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6271 6272 # Get R2eff stats. 6273 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6274 6275 ## Plot R2eff stats 6276 write_stats = True 6277 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6278 6279 # Open stat file. 6280 if write_stats: 6281 if selection == None: 6282 file_name = 'r2eff_stat_all.txt' 6283 else: 6284 file_name = 'r2eff_stat_sel.txt' 6285 path = RDR.results_dir 6286 data = extract_data(file=file_name, dir=path) 6287 6288 # Loop over the lines. 6289 for i, data_i in enumerate(data): 6290 print(i, data_i) 6291 6292 6293 # Do minimisation individual. 6294 if True: 6295 methods = ['FT', 'MDD'] 6296 # Now calculate R2eff. 6297 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6298 6299 min_methods = [['FT'], ['MDD']] 6300 min_list_glob_ini = [[128], range(126, 130, 2)[::-1]] 6301 6302 #min_methods = [['FT']] 6303 #min_list_glob_ini = [[128]] 6304 #selection = ':2,3' 6305 selection = None 6306 6307 for i, methods in enumerate(min_methods): 6308 list_glob_ini = min_list_glob_ini[i] 6309 6310 if True: 6311 # First get data. 6312 if True: 6313 # First load all data. 6314 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6315 6316 # Then set R20 6317 if True: 6318 # Set R20 from min R2eff in preparation for Grid search. 6319 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6320 6321 # Check and print parameters. 6322 if True: 6323 # Print for pipe name 6324 method = methods[0] 6325 glob_ini = list_glob_ini[0] 6326 6327 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6328 RDR.spin_display_params(pipe_name=test_pipe_name) 6329 6330 # Then Grid search. 6331 if True: 6332 # Do Grid search. 6333 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6334 6335 # Then Minimise. 6336 if True: 6337 # Minimise 6338 RDR.opt_max_iterations = int(1e2) 6339 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6340 6341 #print asd 6342 6343 # Plot statistics. 6344 # Try plot some minimisation correlations. 6345 if True: 6346 selections = [None, ':2,3'] 6347 for selection in selections: 6348 # Collect param values. 6349 analysis = 'min_ind' 6350 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6351 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], selection=selection) 6352 6353 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6354 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6355 corr_data = [fig1, fig2] 6356 6357 write_stats = True 6358 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6359 6360 # Open stat file. 6361 if write_stats: 6362 for i, corr_data_i in enumerate(corr_data): 6363 data, methods, glob_inis = corr_data[i] 6364 data_x, data_y = data 6365 method_x, method_y = methods 6366 glob_ini_x, glob_ini_y = glob_inis 6367 6368 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6369 6370 if selection == None: 6371 file_name = file_name_ini + '_all.txt' 6372 else: 6373 file_name = file_name_ini + '_sel.txt' 6374 path = RDR.results_dir 6375 data = extract_data(file=file_name, dir=path) 6376 6377 # Loop over the lines. 6378 for i, data_i in enumerate(data): 6379 print(i, data_i) 6380 6381 # Try plot some minimisation statistics. 6382 if True: 6383 # Collect param values. 6384 #selections = [None, ':2,3'] 6385 selections = [None, ':2,3'] 6386 for selection in selections: 6387 analysis = 'min_ind' 6388 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6389 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], selection=selection) 6390 6391 # Get param stats. 6392 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6393 6394 ## Plot R2eff stats 6395 write_stats = True 6396 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6397 6398 # Open stat file. 6399 if write_stats: 6400 if selection == None: 6401 file_name = '%s_stat_all.txt' % (analysis) 6402 else: 6403 file_name = '%s_stat_sel.txt' % (analysis) 6404 path = RDR.results_dir 6405 data = extract_data(file=file_name, dir=path) 6406 6407 # Loop over the lines. 6408 for i, data_i in enumerate(data): 6409 print(i, data_i) 6410 6411 6412 # Do minimisation clustered. 6413 if True: 6414 methods = ['FT', 'MDD'] 6415 # Now calculate R2eff. 6416 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6417 6418 min_methods = [['FT'], ['MDD']] 6419 min_list_glob_ini = [[128], range(126, 130, 2)[::-1]] 6420 6421 #min_methods = [['FT']] 6422 #min_list_glob_ini = [[128]] 6423 selection = ':2,3' 6424 6425 for i, methods in enumerate(min_methods): 6426 list_glob_ini = min_list_glob_ini[i] 6427 6428 if True: 6429 # First get data. 6430 if True: 6431 # First load all data. 6432 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6433 6434 # Then select spins. 6435 if True: 6436 # Deselect all spins. 6437 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6438 6439 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6440 6441 # Then preset values. 6442 if True: 6443 # Set k_AB for Grid search. 6444 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6445 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6446 6447 # Then set R20 6448 if True: 6449 # Set R20 from min R2eff in preparation for Grid search. 6450 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6451 6452 # Check and print parameters. 6453 if True: 6454 # Print for pipe name 6455 method = methods[0] 6456 glob_ini = list_glob_ini[0] 6457 6458 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6459 RDR.spin_display_params(pipe_name=test_pipe_name) 6460 6461 # Then Grid search. 6462 if True: 6463 # Do Grid search. 6464 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6465 6466 # Then cluster spins. 6467 if True: 6468 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6469 6470 # Then Minimise. 6471 if True: 6472 # Minimise 6473 RDR.opt_max_iterations = int(1e2) 6474 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6475 6476 # Plot statistics. 6477 # Try plot some minimisation correlations. 6478 if True: 6479 selection = ':2,3' 6480 # Collect param values. 6481 analysis = 'min' 6482 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6483 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], selection=selection) 6484 6485 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6486 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6487 corr_data = [fig1, fig2] 6488 6489 write_stats = True 6490 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6491 6492 # Open stat file. 6493 if write_stats: 6494 for i, corr_data_i in enumerate(corr_data): 6495 data, methods, glob_inis = corr_data[i] 6496 data_x, data_y = data 6497 method_x, method_y = methods 6498 glob_ini_x, glob_ini_y = glob_inis 6499 6500 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6501 6502 if selection == None: 6503 file_name = file_name_ini + '_all.txt' 6504 else: 6505 file_name = file_name_ini + '_sel.txt' 6506 path = RDR.results_dir 6507 data = extract_data(file=file_name, dir=path) 6508 6509 # Loop over the lines. 6510 for i, data_i in enumerate(data): 6511 print(i, data_i) 6512 6513 # Try plot some minimisation statistics. 6514 if True: 6515 # Collect param values. 6516 selections = [':2,3'] 6517 for selection in selections: 6518 analysis = 'min' 6519 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6520 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], selection=selection) 6521 6522 # Get param stats. 6523 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6524 6525 ## Plot R2eff stats 6526 write_stats = True 6527 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6528 6529 # Open stat file. 6530 if write_stats: 6531 if selection == None: 6532 file_name = '%s_stat_all.txt' % (analysis) 6533 else: 6534 file_name = '%s_stat_sel.txt' % (analysis) 6535 path = RDR.results_dir 6536 data = extract_data(file=file_name, dir=path) 6537 6538 # Loop over the lines. 6539 for i, data_i in enumerate(data): 6540 print(i, data_i)
6541 6542 6543
6544 - def test_r1rho_kjaergaard_auto(self):
6545 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6546 6547 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6548 6549 This uses the automatic analysis. 6550 6551 """ 6552 6553 # Cluster residues 6554 cluster_ids = [ 6555 ":13@N", 6556 ":15@N", 6557 ":16@N", 6558 ":25@N", 6559 ":26@N", 6560 ":28@N", 6561 ":39@N", 6562 ":40@N", 6563 ":41@N", 6564 ":43@N", 6565 ":44@N", 6566 ":45@N", 6567 ":49@N", 6568 ":52@N", 6569 ":53@N"] 6570 6571 # Load the data. 6572 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6573 6574 # Test some of the sequence. 6575 self.assertEqual(len(cdp.mol), 1) 6576 self.assertEqual(cdp.mol[0].name, None) 6577 self.assertEqual(len(cdp.mol[0].res), 48) 6578 6579 # Test the chemical shift data. 6580 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6581 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6582 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6583 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 6584 6585 i = 0 6586 for spin, spin_id in spin_loop(return_id=True): 6587 # Check the chemical shift. 6588 self.assertEqual(spin.chemical_shift, cs[i]) 6589 6590 # Increment the index. 6591 i += 1 6592 6593 # Initialize counter 6594 i = 0 6595 j = 0 6596 # Count instances of select/deselect 6597 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6598 if curspin.select == True: 6599 i += 1 6600 if curspin.select == False: 6601 j += 1 6602 6603 # Test number of selected/deselected spins. 6604 self.assertEqual(i, len(cluster_ids)) 6605 self.assertEqual(j, 48-len(cluster_ids)) 6606 6607 # Check the initial setup. 6608 self.assertEqual(cdp.mol[0].res[7].num, 13) 6609 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6610 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6611 6612 self.assertEqual(cdp.mol[0].res[9].num, 15) 6613 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6614 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6615 6616 self.assertEqual(cdp.mol[0].res[10].num, 16) 6617 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6618 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6619 6620 self.assertEqual(cdp.mol[0].res[16].num, 25) 6621 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6622 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6623 6624 self.assertEqual(cdp.mol[0].res[17].num, 26) 6625 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6626 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6627 6628 self.assertEqual(cdp.mol[0].res[19].num, 28) 6629 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6630 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6631 6632 self.assertEqual(cdp.mol[0].res[29].num, 39) 6633 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6634 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6635 6636 self.assertEqual(cdp.mol[0].res[30].num, 40) 6637 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6638 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6639 6640 self.assertEqual(cdp.mol[0].res[31].num, 41) 6641 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6642 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6643 6644 self.assertEqual(cdp.mol[0].res[33].num, 43) 6645 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6646 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6647 6648 self.assertEqual(cdp.mol[0].res[34].num, 44) 6649 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6650 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6651 6652 self.assertEqual(cdp.mol[0].res[35].num, 45) 6653 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6654 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6655 6656 self.assertEqual(cdp.mol[0].res[38].num, 49) 6657 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6658 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6659 6660 self.assertEqual(cdp.mol[0].res[41].num, 52) 6661 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6662 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6663 6664 self.assertEqual(cdp.mol[0].res[42].num, 53) 6665 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6666 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6667 6668 # The dispersion models. 6669 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6670 6671 # The grid search size (the number of increments per dimension). 6672 GRID_INC = 4 6673 6674 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6675 MC_NUM = 3 6676 6677 # Model selection technique. 6678 MODSEL = 'AIC' 6679 6680 # Execute the auto-analysis (fast). 6681 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6682 OPT_FUNC_TOL = 1e-1 6683 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6684 OPT_MAX_ITERATIONS = 1000 6685 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6686 6687 result_dir_name = ds.tmpdir 6688 6689 # Make all spins free 6690 for curspin in cluster_ids: 6691 self.interpreter.relax_disp.cluster('free spins', curspin) 6692 # Shut them down 6693 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6694 6695 # Select only a subset of spins for global fitting 6696 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6697 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6698 6699 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6700 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6701 6702 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6703 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6704 6705 # Run the analysis. 6706 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6707 6708 # Check the kex value of residue 52 6709 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6710 6711 # Print results for each model. 6712 print("\n\n################") 6713 print("Printing results") 6714 print("################\n") 6715 for model in MODELS: 6716 # Skip R2eff model. 6717 if model == MODEL_R2EFF: 6718 continue 6719 6720 # Switch to pipe. 6721 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6722 print("\nModel: %s" % (model)) 6723 6724 # Loop over the spins. 6725 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6726 # Generate spin string. 6727 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6728 6729 # Loop over the parameters. 6730 print("Optimised parameters for spin: %s" % (spin_string)) 6731 for param in cur_spin.params + ['chi2']: 6732 # Get the value. 6733 if param in ['r1', 'r2']: 6734 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6735 # Generate the R20 key. 6736 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6737 6738 # Get the value. 6739 value = getattr(cur_spin, param)[r20_key] 6740 6741 # Print value. 6742 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6743 6744 # For all other parameters. 6745 else: 6746 # Get the value. 6747 value = getattr(cur_spin, param) 6748 6749 # Print value. 6750 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6751 6752 # Print the final pipe. 6753 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 6754 print("\nFinal pipe")
6755 6756
6758 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 6759 6760 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6761 6762 This uses the automatic analysis. 6763 6764 """ 6765 6766 # Cluster residues 6767 cluster_ids = [ 6768 ":52@N"] 6769 6770 # Load the data. 6771 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6772 6773 # The dispersion models. 6774 MODELS = [MODEL_R2EFF] 6775 6776 # The grid search size (the number of increments per dimension). 6777 GRID_INC = 4 6778 6779 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6780 MC_NUM = 3 6781 6782 # Model selection technique. 6783 MODSEL = 'AIC' 6784 6785 # Execute the auto-analysis (fast). 6786 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6787 OPT_FUNC_TOL = 1e-1 6788 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6789 OPT_MAX_ITERATIONS = 1000 6790 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6791 6792 result_dir_name = ds.tmpdir 6793 6794 # Make all spins free 6795 for curspin in cluster_ids: 6796 self.interpreter.relax_disp.cluster('free spins', curspin) 6797 # Shut them down 6798 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6799 6800 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6801 6802 # Run the analysis. 6803 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6804 6805 # Check the graphs produced. 6806 graph_comb = [ 6807 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 6808 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 6809 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 6810 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 6811 ] 6812 6813 # Define expected folder names. 6814 result_folders = MODELS 6815 6816 # Assign spin_id. 6817 spin_id = ':52@N' 6818 6819 # Loop over result folders. 6820 for result_folder in result_folders: 6821 # Skip the model R2eff, which does not produce graphs. 6822 if result_folder == MODEL_R2EFF: 6823 continue 6824 6825 # Loop over graphs. 6826 for y_axis, x_axis, interpolate in graph_comb: 6827 # Determine file name: 6828 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6829 6830 # Make the file name. 6831 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6832 6833 # Get the file path. 6834 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 6835 6836 print("Testing file access to graph: %s"%file_path) 6837 self.assert_(access(file_path, F_OK)) 6838 6839 # Start testing all possible combinations of graphs. 6840 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 6841 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 6842 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 6843 6844 result_dir_name = ds.tmpdir 6845 6846 # Loop through all possible combinations of y_axis, x_axis and interpolation. 6847 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 6848 6849 for result_folder in result_folders: 6850 # Skip the model R2eff, which does not produce graphs. 6851 if result_folder == MODEL_R2EFF: 6852 continue 6853 6854 for y_axis in y_axis_types: 6855 for x_axis in x_axis_types: 6856 for interpolate in interpolate_types: 6857 # Determine file name: 6858 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6859 6860 # Make the file name. 6861 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6862 6863 # Write the curves. 6864 dir = result_dir_name+sep+result_folder 6865 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 6866 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 6867 6868 # Get the file path. 6869 file_path = get_file_path(file_name, dir) 6870 6871 # Test the plot file exists. 6872 print("Testing file access to graph: %s"%file_path) 6873 self.assert_(access(file_path, F_OK)) 6874 6875 # Now open, and compare content, line by line. 6876 file_prod = open(file_path) 6877 lines_prod = file_prod.readlines() 6878 file_prod.close() 6879 6880 # Define file to compare against. 6881 dir_comp = data_path+sep+result_folder 6882 file_path_comp = get_file_path(file_name, dir_comp) 6883 file_comp = open(file_path_comp) 6884 lines_comp = file_comp.readlines() 6885 file_comp.close() 6886 6887 # Assert number of lines is equal. 6888 self.assertEqual(len(lines_prod), len(lines_comp)) 6889 for j in range(len(lines_prod)): 6890 # Make the string test 6891 first_char = lines_prod[j][0] 6892 if first_char in ["@", "&"]: 6893 self.assertEqual(lines_prod[j], lines_comp[j]) 6894 else: 6895 # Split string in x, y, error. 6896 # The error would change per run. 6897 x_prod, y_prod, y_prod_err = lines_prod[j].split() 6898 x_comp, y_comp, y_comp_err = lines_comp[j].split() 6899 self.assertAlmostEqual(float(x_prod), float(x_comp)) 6900 self.assertAlmostEqual(float(y_prod), float(y_comp))
6901 6902
6904 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6905 6906 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6907 6908 This uses the automatic analysis, with missing loading R1. 6909 6910 """ 6911 6912 # Cluster residues 6913 cluster_ids = [ 6914 ":13@N", 6915 ":15@N", 6916 ":16@N", 6917 ":25@N", 6918 ":26@N", 6919 ":28@N", 6920 ":39@N", 6921 ":40@N", 6922 ":41@N", 6923 ":43@N", 6924 ":44@N", 6925 ":45@N", 6926 ":49@N", 6927 ":52@N", 6928 ":53@N"] 6929 6930 # Load the data. 6931 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 6932 6933 # The dispersion models. 6934 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6935 6936 # The grid search size (the number of increments per dimension). 6937 GRID_INC = None 6938 6939 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6940 MC_NUM = 3 6941 6942 # Model selection technique. 6943 MODSEL = 'AIC' 6944 6945 # Execute the auto-analysis (fast). 6946 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6947 OPT_FUNC_TOL = 1e-25 6948 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6949 OPT_MAX_ITERATIONS = 10000000 6950 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6951 6952 result_dir_name = ds.tmpdir 6953 6954 # Make all spins free 6955 for curspin in cluster_ids: 6956 self.interpreter.relax_disp.cluster('free spins', curspin) 6957 # Shut them down 6958 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6959 6960 # Select only a subset of spins for global fitting 6961 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6962 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6963 6964 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6965 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6966 6967 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6968 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6969 6970 # Point to directory with R2eff values, with 2000 MC simulations. 6971 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 6972 6973 r1_fit = True 6974 6975 # Run the analysis. 6976 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 6977 6978 # Verify the data. 6979 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
6980 6981
6982 - def test_r2eff_read(self):
6983 """Test the operation of the relax_disp.r2eff_read user function.""" 6984 6985 # The path to the data files. 6986 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 6987 6988 # Read the sequence data. 6989 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 6990 6991 # The ID. 6992 id = 'test' 6993 6994 # Set up the metadata. 6995 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 6996 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 6997 6998 # Try reading the file. 6999 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7000 7001 # Check the global data. 7002 data = [ 7003 ['cpmg_frqs', {'test': 66.667}], 7004 ['cpmg_frqs_list', [66.667]], 7005 ['dispersion_points', 1], 7006 ['exp_type', {'test': 'SQ CPMG'}], 7007 ['exp_type_list', ['SQ CPMG']], 7008 ['spectrometer_frq', {'test': 800000000.0}], 7009 ['spectrometer_frq_count', 1], 7010 ['spectrometer_frq_list', [800000000.0]], 7011 ['spectrum_ids', ['test']] 7012 ] 7013 for name, value in data: 7014 # Does it exist? 7015 self.assert_(hasattr(cdp, name)) 7016 7017 # Check the object. 7018 obj = getattr(cdp, name) 7019 self.assertEqual(obj, value) 7020 7021 # Check the spin data. 7022 data = [ 7023 [1, 2.3035747e+04, 8.5467725e+01], 7024 [2, 9.9629762e+04, 2.8322033e+02], 7025 [3, 9.5663137e+04, 2.8632929e+02], 7026 [4, 1.7089893e+05, 3.1089428e+02], 7027 [5, 4.7323876e+04, 1.0084269e+02], 7028 [6, 2.0199122e+04, 1.0135220e+02], 7029 [7, 1.6655488e+05, 3.1609061e+02], 7030 [8, 9.0061074e+04, 1.9176585e+02], 7031 [10, 8.4726204e+04, 2.8898155e+02], 7032 [11, 1.5050233e+05, 4.3138029e+02], 7033 [12, 9.2998531e+04, 3.0440191e+02], 7034 [13, 1.6343507e+05, 3.3144097e+02], 7035 [14, 1.0137301e+05, 3.7314642e+02], 7036 [15, 8.3407837e+04, 1.6546473e+02], 7037 [16, 1.3819126e+05, 3.3388517e+02], 7038 [17, 1.1010490e+05, 3.5639222e+02], 7039 [18, 9.4324035e+04, 3.2343585e+02], 7040 [19, 1.1135179e+05, 3.0706671e+02], 7041 [20, 7.6339410e+04, 1.7377460e+02], 7042 [21, 6.2008453e+04, 1.7327150e+02], 7043 [22, 1.0590404e+05, 2.4814635e+02], 7044 [23, 1.0630198e+05, 2.3601100e+02], 7045 [24, 7.2996320e+04, 1.4952465e+02], 7046 [25, 9.5486742e+04, 2.7080766e+02], 7047 [26, 5.8067989e+04, 1.6820462e+02], 7048 [27, -1.7168510e+04, 2.2519560e+02], 7049 [28, 1.6891473e+05, 2.3497525e+02], 7050 [29, 9.4038555e+04, 2.0357593e+02], 7051 [30, 2.1386951e+04, 2.2153532e+02], 7052 [31, 9.3982899e+04, 2.0937056e+02], 7053 [32, 8.6097484e+04, 2.3868467e+02], 7054 [33, 1.0194337e+05, 2.7370704e+02], 7055 [34, 8.5683111e+04, 2.0838076e+02], 7056 [35, 8.6985768e+04, 2.0889310e+02], 7057 [36, 8.6011237e+04, 1.7498390e+02], 7058 [37, 1.0984097e+05, 2.7622998e+02], 7059 [38, 8.7017879e+04, 2.6547994e+02], 7060 [39, 9.1682649e+04, 5.2777676e+02], 7061 [40, 7.6370440e+04, 1.9873214e+02], 7062 [41, 9.1393531e+04, 2.4483824e+02], 7063 [42, 1.1017111e+05, 2.8020699e+02], 7064 [43, 9.4552366e+04, 3.4394150e+02], 7065 [44, 1.2858281e+05, 6.8449252e+02], 7066 [45, 7.4583525e+04, 1.9544210e+02], 7067 [46, 9.2087490e+04, 2.0491066e+02], 7068 [47, 9.7507255e+04, 2.5162839e+02], 7069 [48, 1.0033842e+05, 2.7566430e+02], 7070 [49, 1.3048305e+05, 2.6797466e+02], 7071 [50, 1.0546796e+05, 1.9304384e+02], 7072 [51, 9.3099697e+04, 2.0773311e+02], 7073 [52, 4.6863758e+04, 1.3169068e+02], 7074 [53, 6.1055806e+04, 1.5448477e+02], 7075 [55, 6.8629994e+04, 1.6868673e+02], 7076 [56, 1.1005552e+05, 2.1940465e+02], 7077 [57, 1.0572760e+05, 1.9768486e+02], 7078 [58, 1.1176950e+05, 3.0009610e+02], 7079 [59, 9.8758603e+04, 3.3803895e+02], 7080 [60, 9.9517201e+04, 3.5137994e+02], 7081 [61, 5.4357946e+04, 2.5896579e+02], 7082 [62, 1.0899978e+05, 2.8720371e+02], 7083 [63, 8.4549759e+04, 4.1401837e+02], 7084 [64, 5.5014550e+04, 2.1135781e+02], 7085 [65, 8.0569666e+04, 2.3249709e+02], 7086 [66, 1.2936610e+05, 3.5218725e+02], 7087 [67, 3.6438010e+04, 8.7924003e+01], 7088 [70, 3.8763157e+04, 1.3325040e+02], 7089 [71, 8.5711411e+04, 2.9316183e+02], 7090 [72, 3.3211541e+04, 1.2182123e+02], 7091 [73, 3.2070576e+04, 1.2305430e+02] 7092 ] 7093 for res_num, value, error in data: 7094 # Get the spin. 7095 spin = return_spin(spin_id=":%s"%res_num) 7096 7097 # Check the values. 7098 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7099 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7100 7101
7102 - def test_r2eff_read_spin(self):
7103 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7104 7105 # The path to the data files. 7106 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7107 7108 # Generate the sequence. 7109 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7110 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7111 self.interpreter.spin.isotope('1H', spin_id='@H') 7112 self.interpreter.spin.isotope('15N', spin_id='@N') 7113 7114 # Build the experiment IDs. 7115 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7116 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7117 ids = [] 7118 for value in H_disp_points: 7119 ids.append('1H_CPMG_%s' % value) 7120 for value in N_disp_points: 7121 ids.append('15N_CPMG_%s' % value) 7122 print("\n\nThe experiment IDs are %s." % ids) 7123 7124 # Set up the metadata for the experiments. 7125 for id in ids: 7126 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7127 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7128 for value in H_disp_points: 7129 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7130 for value in N_disp_points: 7131 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7132 7133 # Loop over the experiments. 7134 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7135 # Try reading the file. 7136 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7137 7138 # Check the global data. 7139 data = [ 7140 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7141 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7142 ['dispersion_points', 24], 7143 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7144 ['exp_type_list', ['SQ CPMG']], 7145 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7146 ['spectrometer_frq_count', 1], 7147 ['spectrometer_frq_list', [500000000.0]], 7148 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7149 ] 7150 for name, value in data: 7151 # Does it exist? 7152 self.assert_(hasattr(cdp, name)) 7153 7154 # Check the object. 7155 obj = getattr(cdp, name) 7156 if not isinstance(data, dict): 7157 self.assertEqual(obj, value) 7158 7159 # Check the global dictionary data. 7160 else: 7161 for id in ids: 7162 self.assertEqual(obj[id], value[id]) 7163 7164 # Check the spin data. 7165 h_data = [ 7166 [ 67.0, 21.47924, 0.42958], 7167 [ 133.0, 16.73898, 0.33478], 7168 [ 267.0, 9.97357, 0.19947], 7169 [ 400.0, 8.23877, 0.24737], 7170 [ 533.0, 7.59290, 0.24263], 7171 [ 667.0, 7.45843, 0.24165], 7172 [ 800.0, 7.11222, 0.23915], 7173 [ 933.0, 7.40880, 0.24129], 7174 [1067.0, 6.55191, 0.16629], 7175 [1600.0, 6.72177, 0.23637], 7176 [2133.0, 7.09629, 0.23904], 7177 [2667.0, 7.14675, 0.23940] 7178 ] 7179 for disp_point, value, error in h_data: 7180 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7181 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7182 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7183 n_data = [ 7184 [ 50.0, 27.15767, 0.54315], 7185 [ 100.0, 26.55781, 0.53116], 7186 [ 150.0, 24.73462, 0.49469], 7187 [ 200.0, 20.98617, 0.41972], 7188 [ 250.0, 17.82442, 0.35649], 7189 [ 300.0, 15.55352, 0.31107], 7190 [ 350.0, 13.78958, 0.27579], 7191 [ 400.0, 12.48334, 0.24967], 7192 [ 500.0, 11.55724, 0.23114], 7193 [ 600.0, 10.53874, 0.21077], 7194 [ 700.0, 10.07395, 0.20148], 7195 [ 800.0, 9.62952, 0.19259], 7196 [ 900.0, 9.49994, 0.19000], 7197 [1000.0, 8.71350, 0.17427] 7198 ] 7199 for disp_point, value, error in n_data: 7200 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7201 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7202 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7203 7204
7205 - def test_r2eff_fit_fixed_time(self):
7206 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7207 7208 # Execute the script. 7209 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7210 7211
7212 - def test_read_r2eff(self):
7213 """Test the reading of a file containing r2eff values.""" 7214 7215 # Create the sequence data, and name the spins. 7216 self.interpreter.residue.create(1, 'Gly') 7217 self.interpreter.residue.create(2, 'Gly') 7218 self.interpreter.residue.create(3, 'Gly') 7219 7220 # Read the file. 7221 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7222 7223 # Test the data. 7224 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7225 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7226 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7227 7228
7230 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7231 7232 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7233 7234 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7235 'SOD1-WT' CPMG data to the CR72 dispersion model. 7236 7237 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7238 Data is for experiment at 25 degree Celcius. 7239 """ 7240 7241 # Base data setup. 7242 pipe_name = 'base pipe' 7243 pipe_type = 'relax_disp' 7244 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7245 select_spin_index = list(range(0, 1)) 7246 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7247 7248 # Generate r20 key. 7249 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7250 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7251 7252 ## Now prepare for MODEL calculation. 7253 MODEL = "CR72" 7254 7255 # Change pipe. 7256 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7257 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7258 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7259 7260 # Then select model. 7261 self.interpreter.relax_disp.select_model(model=MODEL) 7262 7263 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7264 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7265 7266 # Test result, for normal run. 7267 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7268 # Get the spin_params. 7269 spin_params = spin.params 7270 7271 # Defined fixed values for testing. 7272 if spin_id == ":10@N": 7273 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7274 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7275 7276 # Print out. 7277 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7278 7279 # Testing the r2 values for the different fields are not the same. 7280 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7281 7282 # Test values are larger than 0. 7283 self.assert_(spin.r2[r20_key_600] > 0.0) 7284 self.assert_(spin.r2[r20_key_500] > 0.0) 7285 7286 # Loop over the experiment settings. 7287 r2eff_600 = [] 7288 r2eff_500 = [] 7289 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7290 # Create the data key. 7291 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7292 7293 # Extract the r2 eff data. 7294 r2eff = spin.r2eff[data_key] 7295 if frq == 599.8908617*1E6: 7296 r2eff_600.append(r2eff) 7297 elif frq == 499.862139*1E6: 7298 r2eff_500.append(r2eff) 7299 7300 # Sort values. 7301 r2eff_600.sort() 7302 r2eff_500.sort() 7303 7304 # Test values again. 7305 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7306 print(r2eff_600) 7307 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7308 print("") 7309 7310 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7311 print(r2eff_500) 7312 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7313 print("") 7314 7315 print("###########################################") 7316 print("Trying GRID SEARCH for minimum R2eff values") 7317 7318 ### Test just the Grid search. 7319 GRID_INC = 5 7320 7321 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7322 7323 ### Then test the value.set function. 7324 # Change pipe. 7325 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7326 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7327 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7328 7329 # Then select model. 7330 self.interpreter.relax_disp.select_model(model=MODEL) 7331 7332 # Then set the standard parameter values. 7333 for param in spin_params: 7334 print("Setting standard parameter for param: %s"%param) 7335 self.interpreter.value.set(param=param, index=None) 7336 7337 # Test result, for normal run. 7338 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7339 # Print out. 7340 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7341 7342 # Testing the r2 values. 7343 self.assertEqual(spin.r2[r20_key_600], 10.00) 7344 self.assertEqual(spin.r2[r20_key_500], 10.00) 7345 self.assertEqual(spin.pA, 0.9) 7346 self.assertEqual(spin.dw, 1.0) 7347 self.assertEqual(spin.kex, 1000.0) 7348 7349 print("###########################################") 7350 print("Trying GRID SEARCH for standard R2eff values") 7351 7352 ### Test just the Grid search. 7353 GRID_INC = 5 7354 7355 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7356 7357 ### Run auto_analysis. 7358 # The grid search size (the number of increments per dimension). 7359 GRID_INC = 5 7360 7361 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7362 MC_NUM = 3 7363 7364 # Model selection technique. 7365 MODSEL = 'AIC' 7366 7367 # Execute the auto-analysis (fast). 7368 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7369 OPT_FUNC_TOL = 1e-1 7370 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7371 OPT_MAX_ITERATIONS = 1000 7372 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7373 7374 # Run the analysis. 7375 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7376 7377
7378 - def test_show_apod_extract(self):
7379 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7380 7381 # The path to the data files. 7382 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7383 7384 # Define file name. 7385 file_name = '128_0_FT.ft2' 7386 7387 # Call function. 7388 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7389 7390 # Define how output should look like. 7391 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7392 # Dont test lines which can differ. 7393 show_apod_ver = [ 7394 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7395 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7396 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7397 '', 7398 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7399 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7400 #'', 7401 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7402 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7403 7404 for i, line in enumerate(show_apod_ver): 7405 line_ver = get_output[i] 7406 7407 print(line) 7408 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7409 continue 7410 # Make the string test 7411 self.assertEqual(line, line_ver)
7412 7413
7414 - def test_show_apod_rmsd(self):
7415 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7416 7417 # The path to the data files. 7418 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7419 7420 # Define file name. 7421 file_name = '128_0_FT.ft2' 7422 7423 # Call function. 7424 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7425 7426 # Assert. 7427 self.assertEqual(rmsd, 8583.41)
7428 7429
7431 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7432 7433 # The path to the data files. 7434 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7435 7436 # Call function, and get all file names. 7437 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7438 7439 # Loop over file_paths. 7440 for wfile_path in wfile_paths: 7441 # Open the file. 7442 get_data = extract_data(file=wfile_path) 7443 7444 # Extract line 0, column 0. 7445 test = float(get_data[0][0]) 7446 7447 # Assert. 7448 self.assertEqual(test, 8583.41)
7449 7450
7452 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7453 7454 # The path to the data files. 7455 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7456 7457 # Define file name. 7458 file_name = '128_0_FT.ft2' 7459 7460 # Call function, and get file name. 7461 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7462 7463 # Open the file. 7464 get_data = extract_data(file=wfile_path) 7465 7466 # Extract line 0, column 0. 7467 test = float(get_data[0][0]) 7468 7469 # Assert. 7470 self.assertEqual(test, 8583.41)
7471 7472
7474 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7475 7476 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7477 'SOD1-WT' CPMG data to the CR72 dispersion model. 7478 7479 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7480 Data is for experiment at 25 degree Celcius. 7481 7482 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7483 """ 7484 7485 # Base data setup. 7486 pipe_name = 'base pipe' 7487 pipe_type = 'relax_disp' 7488 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7489 select_spin_index = list(range(0, 1)) 7490 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7491 7492 # Define replicated 7493 repl_A = ['Z_A1', 'Z_A15'] 7494 repl_B = ['Z_B1', 'Z_B18'] 7495 7496 # Loop over spectrum ID, and sort them 7497 spectrum_ids_A = [] 7498 spectrum_ids_B = [] 7499 for spectrum_id in cdp.spectrum_ids: 7500 if "A" in spectrum_id: 7501 spectrum_ids_A.append(spectrum_id) 7502 elif "B" in spectrum_id: 7503 spectrum_ids_B.append(spectrum_id) 7504 7505 # To clean up old error analysis, delete attributes 7506 delattr(cdp, "var_I") 7507 delattr(cdp, "sigma_I") 7508 7509 # Perform error analysis 7510 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7511 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7512 7513 # Loop over spins, save errors to list 7514 Errors_A_B = [] 7515 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7516 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7517 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7518 Errors_A_B.append([A_err, B_err]) 7519 7520 # To clean up old error analysis, delete attributes 7521 delattr(cdp, "var_I") 7522 delattr(cdp, "sigma_I") 7523 7524 # Perform error analysis. Order is important 7525 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7526 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7527 7528 # Loop over spins, save errors to list 7529 Errors_B_A = [] 7530 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7531 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7532 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7533 Errors_B_A.append([A_err, B_err]) 7534 7535 # Make test for order of error 7536 for i in range(len(Errors_A_B)): 7537 Error_A_B = Errors_A_B[i] 7538 Error_B_A = Errors_B_A[i] 7539 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7540 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7541 7542 # Make further tests for fixed values 7543 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7544 std_A_fix = 2785.7263335738567 7545 7546 for id_A in spectrum_ids_A: 7547 self.assertEqual(cdp.sigma_I[id_A], std_A) 7548 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7549 7550 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7551 std_B_fix = 4967.3772030667988 7552 7553 for id_B in spectrum_ids_B: 7554 self.assertEqual(cdp.sigma_I[id_B], std_B) 7555 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7556 7557
7558 - def test_sod1wt_t25_to_cr72(self):
7559 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7560 7561 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7562 'SOD1-WT' CPMG data to the CR72 dispersion model. 7563 7564 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7565 Data is for experiment at 25 degree Celcius. 7566 """ 7567 7568 # Base data setup. 7569 pipe_name = 'base pipe' 7570 pipe_type = 'relax_disp' 7571 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7572 select_spin_index = list(range(0, 2)) 7573 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7574 7575 # Generate r20 key. 7576 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7577 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7578 7579 ## Now prepare for MODEL calculation. 7580 MODEL = "CR72" 7581 7582 # Change pipe. 7583 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7584 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7585 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7586 7587 # Then select model. 7588 self.interpreter.relax_disp.select_model(model=MODEL) 7589 7590 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7591 GRID_INC = 7 7592 7593 # Store grid and minimisations results. 7594 grid_results = [] 7595 mini_results = [] 7596 clust_results = [] 7597 7598 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7599 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7600 7601 # Deselect insignificant spins. 7602 self.interpreter.relax_disp.insignificance(level=1.0) 7603 7604 # Perform Grid Search. 7605 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7606 7607 # Store result. 7608 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7609 # Store grid results. 7610 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7611 7612 ## Now do minimisation. 7613 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7614 set_func_tol = 1e-9 7615 set_max_iter = 100000 7616 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7617 7618 # Store result. 7619 pA_values = [] 7620 kex_values = [] 7621 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7622 # Store minimisation results. 7623 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7624 7625 # Store pA values. 7626 pA_values.append(spin.pA) 7627 7628 # Store kex values. 7629 kex_values.append(spin.kex) 7630 7631 print("\n# Now print before and after minimisation.\n") 7632 7633 # Print results. 7634 for i in range(len(grid_results)): 7635 # Get values. 7636 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7637 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7638 7639 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7640 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7641 7642 ## Prepare for clustering 7643 # Change pipe. 7644 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7645 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7646 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7647 7648 # Then select model. 7649 self.interpreter.relax_disp.select_model(model=MODEL) 7650 7651 # Define cluster id. 7652 cluster_id = 'clust' 7653 7654 # Loop over spins to cluster them. 7655 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7656 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7657 7658 # Copy over values. 7659 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7660 7661 # Test the median values is correct 7662 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7663 print(pA_values) 7664 # The the median pA value returned. 7665 self.assertEqual(median(pA_values), spin.pA) 7666 7667 # The the median kex value returned. 7668 self.assertEqual(median(kex_values), spin.kex) 7669 7670 ## Now do minimisation. 7671 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7672 7673 # Store result. 7674 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7675 # Store clust results. 7676 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7677 7678 # Store the outcome of the clustering minimisation. 7679 clust_pA = spin.pA 7680 clust_kex = spin.kex 7681 7682 print("\n# Now testing.\n") 7683 7684 # Define results 7685 test_res = {} 7686 test_res[':10@N'] = {} 7687 test_res[':10@N']['r2600'] = 18.429755324773360 7688 test_res[':10@N']['r2500'] = 16.981349161968630 7689 test_res[':10@N']['dw'] = 2.700755859433969 7690 test_res[':10@N']['pA'] = 0.971531659288657 7691 test_res[':10@N']['kex'] = 3831.766337047963134 7692 test_res[':11@N'] = {} 7693 test_res[':11@N']['r2600'] = 18.193409421115213 7694 test_res[':11@N']['r2500'] = 17.308838135567765 7695 test_res[':11@N']['dw'] = 2.706650302761793 7696 test_res[':11@N']['pA'] = 0.971531659288657 7697 test_res[':11@N']['kex'] = 3831.766337047963134 7698 7699 # Then make tests. 7700 for i in range(len(grid_results)): 7701 # Get values. 7702 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7703 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7704 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7705 7706 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7707 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7708 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 7709 7710 # Make tests. 7711 self.assertEqual(clust_pA, c_pA) 7712 self.assertEqual(clust_kex, c_kex) 7713 7714 # Test values. 7715 if c_spin_id in test_res: 7716 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7717 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7718 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7719 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7720 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7721 7722 # Save disp graph to temp. 7723 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7724 7725
7727 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7728 7729 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7730 'SOD1-WT' CPMG data to the CR72 dispersion model. 7731 7732 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7733 Data is for experiment at 25 degree Celcius. 7734 """ 7735 7736 # Base data setup. 7737 pipe_name = 'base pipe' 7738 pipe_type = 'relax_disp' 7739 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7740 select_spin_index = list(range(0, 2)) 7741 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7742 7743 # Generate r20 key. 7744 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7745 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7746 7747 # Cluster everything, to analyse together. 7748 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 7749 7750 # Write input 7751 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 7752 7753 # Check the r2eff set files. 7754 print("\nChecking the R2eff input set files.") 7755 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 7756 7757 # First check file exists 7758 for dir, file in files: 7759 print(dir+sep+file) 7760 self.assert_(access(dir+sep+file, F_OK)) 7761 7762 # Define how files should look like 7763 data_set_600 = [ 7764 "60.8272464287\n", 7765 "0.06\n", 7766 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7767 "# G10\n", 7768 " 33.333 26.53556078711 0.5236104771163\n", 7769 " 66.667 25.29735243318 0.48766574122\n", 7770 " 100 25.09470361403 0.4820438864671\n", 7771 " 133.333 25.15603274331 0.4837377286085\n", 7772 " 166.667 24.27213341753 0.4599457904395\n", 7773 " 200 24.00364120328 0.4529773198905\n", 7774 " 266.667 24.03511395168 0.4537880662536\n", 7775 " 300 23.04761040024 0.4291039120557\n", 7776 " 333.333 22.95530300787 0.4268745963972\n", 7777 " 400 23.06158810662 0.4294426293624\n", 7778 " 466.667 22.26799054092 0.4106809618644\n", 7779 " 533.333 21.99851418823 0.4045232104735\n", 7780 " 666.667 21.19651570955 0.3868136173831\n", 7781 " 833.333 20.30938498379 0.3682604887899\n", 7782 " 1000 20.28273252609 0.367719392568\n", 7783 "# D11\n", 7784 " 33.333 24.76520269878 0.5026475808706\n", 7785 " 66.667 24.8773107448 0.5058752916906\n", 7786 " 100 24.90357815239 0.5066348551479\n", 7787 " 133.333 23.7782506151 0.4751950583865\n", 7788 " 166.667 23.68548762076 0.4727017128631\n", 7789 " 200 23.58629651618 0.4700517377679\n", 7790 " 266.667 23.47734671187 0.4671601744044\n", 7791 " 300 24.08647493772 0.4835855560598\n", 7792 " 333.333 22.98314371029 0.4542918950801\n", 7793 " 400 22.80339361568 0.4497107885587\n", 7794 " 466.667 22.91634335366 0.4525833037874\n", 7795 " 533.333 22.59774140046 0.4445334311324\n", 7796 " 666.667 20.9177750759 0.4046955726046\n", 7797 " 833.333 20.71792550566 0.4002363835007\n", 7798 " 1000 19.54080006349 0.3751112751853\n", 7799 ] 7800 7801 # Check data_set_600 7802 file = open(files[0][0]+sep+files[0][1]) 7803 lines = file.readlines() 7804 file.close() 7805 self.assertEqual(len(data_set_600), len(lines)) 7806 for i in range(len(data_set_600)): 7807 # Make the string test 7808 self.assertEqual(data_set_600[i], lines[i]) 7809 7810 # Define how files should look like 7811 data_set_500 = [ 7812 "50.6846152368\n", 7813 "0.04\n", 7814 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7815 "# G10\n", 7816 " 50 22.28084307393 0.2944966344183\n", 7817 " 100 21.93494977761 0.2910362768307\n", 7818 " 150 21.09850032232 0.282892238351\n", 7819 " 200 20.86493960397 0.2806737853646\n", 7820 " 250 20.75287269752 0.2796178205016\n", 7821 " 300 20.25597152406 0.2750013546989\n", 7822 " 350 19.92172163467 0.2719555756504\n", 7823 " 400 19.97712052922 0.272457105051\n", 7824 " 450 19.46807010415 0.2678972122793\n", 7825 " 500 19.76875460947 0.2705774849203\n", 7826 " 550 19.39161367402 0.2672216964327\n", 7827 " 600 19.03949517697 0.2641417899694\n", 7828 " 650 19.12218812132 0.2648605059901\n", 7829 " 700 19.01037461457 0.2638893584683\n", 7830 " 800 18.83395162904 0.2623674321143\n", 7831 " 900 18.47529972436 0.2593123604687\n", 7832 " 1000 18.5252023121 0.2597343394038\n", 7833 "# D11\n", 7834 " 50 22.15403890237 0.3285588379827\n", 7835 " 100 21.80946781746 0.3247185598713\n", 7836 " 150 21.77715415505 0.324361526682\n", 7837 " 200 21.41647464235 0.3204122024881\n", 7838 " 250 21.17099940822 0.3177616325958\n", 7839 " 300 21.03740030577 0.3163316496664\n", 7840 " 350 20.95393648281 0.3154427665172\n", 7841 " 400 20.93311399332 0.315221543436\n", 7842 " 450 20.18219905222 0.3073848655291\n", 7843 " 500 19.93599065085 0.3048744697057\n", 7844 " 550 19.68475725452 0.3023424499113\n", 7845 " 600 19.33575433934 0.2988741928798\n", 7846 " 650 19.53915692194 0.3008886196853\n", 7847 " 700 19.2018754351 0.2975587767134\n", 7848 " 800 18.82360965368 0.2938866923878\n", 7849 " 900 18.71861761238 0.2928790380131\n", 7850 " 1000 17.95878049287 0.2857341721151\n", 7851 ] 7852 7853 # Check data_set_500 7854 file = open(files[1][0]+sep+files[1][1]) 7855 lines = file.readlines() 7856 file.close() 7857 self.assertEqual(len(data_set_500), len(lines)) 7858 for i in range(len(data_set_500)): 7859 # Make the string test 7860 self.assertEqual(data_set_500[i], lines[i]) 7861 7862 # Test local dir tests. This will be turned off in system test. 7863 turn_on_local_dir_test = False 7864 7865 if turn_on_local_dir_test: 7866 ## Now check to local folder with None argument. 7867 # Write input 7868 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 7869 7870 # Check the r2eff set files. 7871 print("\nChecking the R2eff input set files.") 7872 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 7873 7874 # First check file exists 7875 for dir, file in files: 7876 print(dir+sep+file) 7877 self.assert_(access(dir+sep+file, F_OK)) 7878 7879 ## Now check to local folder with dir argument. 7880 # Write input 7881 set_dir = "Test_ShereKhan" 7882 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 7883 7884 # Check the r2eff set files. 7885 print("\nChecking the R2eff input set files.") 7886 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 7887 7888 # First check file exists 7889 for dir, file in files: 7890 print(dir+sep+file) 7891 self.assert_(access(dir+sep+file, F_OK))
7892 7893
7894 - def test_sprangers_data_to_mmq_cr72(self, model=None):
7895 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 7896 7897 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 7898 """ 7899 7900 # Reset. 7901 self.interpreter.reset() 7902 7903 # Create the data pipe and load the base data. 7904 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 7905 self.interpreter.state.load(data_path+sep+'r2eff_values') 7906 7907 # The model data pipe. 7908 model = 'MMQ CR72' 7909 pipe_name = "%s - relax_disp" % model 7910 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 7911 self.interpreter.pipe.switch(pipe_name=pipe_name) 7912 7913 # Set the model. 7914 self.interpreter.relax_disp.select_model(model=model) 7915 7916 # Cluster everything. 7917 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 7918 7919 # Copy the data. 7920 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 7921 7922 # Alias the spins. 7923 spin135S = cdp.mol[0].res[0].spin[0] 7924 spin135F = cdp.mol[0].res[0].spin[1] 7925 spin137S = cdp.mol[0].res[1].spin[0] 7926 spin137F = cdp.mol[0].res[1].spin[1] 7927 7928 # The R20 keys. 7929 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 7930 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 7931 7932 # Set the cluster specific parameters (only for the first spin). 7933 spin135S.pA = 0.836591763632 7934 spin135S.kex = 241.806525261 7935 7936 # Set the initial parameter values. 7937 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 7938 spin135S.dw = 0.583003118785 7939 spin135S.dwH = 0.0361441944301 7940 7941 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 7942 spin135F.dw = 0.805849745104 7943 spin135F.dwH = 0.0215791945715 7944 7945 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 7946 spin137S.dw = 0.688107568372 7947 spin137S.dwH = 0.0344463604043 7948 7949 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 7950 spin137F.dw = 0.94978299907 7951 spin137F.dwH = 1.4818877939e-07 7952 7953 # Low precision optimisation. 7954 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 7955 7956 # Printout. 7957 print("\n\nOptimised parameters:\n") 7958 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 7959 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 7960 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 7961 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 7962 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 7963 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 7964 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 7965 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 7966 print("\n # Set the cluster specific parameters (only for the first spin).") 7967 print(" spin135S.pA = %s" % spin135S.pA) 7968 print(" spin135S.kex = %s" % spin135S.kex) 7969 print("\n # Set the initial parameter values.") 7970 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 7971 print(" spin135S.dw = %s" % spin135S.dw) 7972 print(" spin135S.dwH = %s" % spin135S.dwH) 7973 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 7974 print(" spin135F.dw = %s" % spin135F.dw) 7975 print(" spin135F.dwH = %s" % spin135F.dwH) 7976 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 7977 print(" spin137S.dw = %s" % spin137S.dw) 7978 print(" spin137S.dwH = %s" % spin137S.dwH) 7979 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 7980 print(" spin137F.dw = %s" % spin137F.dw) 7981 print(" spin137F.dwH = %s" % spin137F.dwH) 7982 7983 # Checks for residue :135S. 7984 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 7985 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 7986 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 7987 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 7988 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 7989 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 7990 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 7991 7992 # Checks for residue :135F. 7993 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 7994 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 7995 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 7996 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 7997 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 7998 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 7999 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8000 8001 # Checks for residue :137S. 8002 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8003 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8004 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8005 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8006 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8007 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8008 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8009 8010 # Checks for residue :137F. 8011 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8012 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8013 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8014 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8015 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8016 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8017 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8018 8019
8020 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8021 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8022 8023 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8024 """ 8025 8026 # Reset. 8027 self.interpreter.reset() 8028 8029 # Create the data pipe and load the base data. 8030 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8031 self.interpreter.state.load(data_path+sep+'r2eff_values') 8032 8033 # The model data pipe. 8034 model = 'NS MMQ 2-site' 8035 pipe_name = "%s - relax_disp" % model 8036 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8037 self.interpreter.pipe.switch(pipe_name=pipe_name) 8038 8039 # Set the model. 8040 self.interpreter.relax_disp.select_model(model=model) 8041 8042 # Cluster everything. 8043 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8044 8045 # Copy the data. 8046 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8047 8048 # Alias the spins. 8049 spin135S = cdp.mol[0].res[0].spin[0] 8050 spin135F = cdp.mol[0].res[0].spin[1] 8051 spin137S = cdp.mol[0].res[1].spin[0] 8052 spin137F = cdp.mol[0].res[1].spin[1] 8053 8054 # The R20 keys. 8055 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8056 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8057 8058 # Set the cluster specific parameters (only for the first spin). 8059 spin135S.pA = 0.847378444499757 8060 spin135S.kex = 264.055604934724329 8061 8062 # Set the initial parameter values. 8063 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8064 spin135S.dw = 0.585574008745351 8065 spin135S.dwH = 0.000000000000002 8066 8067 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8068 spin135F.dw = 0.856699277665748 8069 spin135F.dwH = 0.000000000582587 8070 8071 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8072 spin137S.dw = 0.772904450844973 8073 spin137S.dwH = 0.183351478512970 8074 8075 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8076 spin137F.dw = 0.984568590342831 8077 spin137F.dwH = 0.000000001993458 8078 8079 # Low precision optimisation. 8080 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8081 8082 # Printout. 8083 print("\n\nOptimised parameters:\n") 8084 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8085 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8086 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8087 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8088 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8089 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8090 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8091 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8092 8093 # FIXME: Remove this temporary return and properly check the results. 8094 return 8095 8096 # Checks for residue :135S. 8097 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8098 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8099 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8100 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8101 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8102 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8103 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8104 8105 # Checks for residue :135F. 8106 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8107 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8108 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8109 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8110 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8111 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8112 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8113 8114 # Checks for residue :137S. 8115 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8116 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8117 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8118 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8119 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8120 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8121 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8122 8123 # Checks for residue :137F. 8124 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8125 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8126 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8127 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8128 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8129 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8130 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8131 8132
8133 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8134 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8135 8136 # Setup the data. 8137 self.setup_tp02_data_to_ns_r1rho_2site() 8138 8139 # Alias the spins. 8140 spin1 = cdp.mol[0].res[0].spin[0] 8141 spin2 = cdp.mol[0].res[1].spin[0] 8142 8143 # The R20 keys. 8144 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8145 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8146 8147 # Checks for residue :1. 8148 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8149 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8150 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8151 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8152 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8153 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8154 8155 # Checks for residue :2. 8156 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8157 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8158 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8159 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8160 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8161 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8162 8163
8164 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8165 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8166 8167 # Setup the data. 8168 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8169 8170 # Alias the spins. 8171 spin1 = cdp.mol[0].res[0].spin[0] 8172 spin2 = cdp.mol[0].res[1].spin[0] 8173 8174 # The R20 keys. 8175 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8176 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8177 8178 # Checks for residue :1. 8179 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8180 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8181 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8182 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8183 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8184 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8185 8186 # Checks for residue :2. 8187 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8188 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8189 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8190 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8191 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8192 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8193 8194
8195 - def test_tp02_data_to_mp05(self):
8196 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8197 8198 # Fixed time variable and the models. 8199 ds.fixed = True 8200 ds.models = ['R2eff', 'MP05'] 8201 8202 # Execute the script. 8203 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8204 8205 # Switch back to the data pipe for the optimisation. 8206 self.interpreter.pipe.switch('MP05 - relax_disp') 8207 8208 # The equivalent MP05 parameters. 8209 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8210 pA = [0.775055484521586, 0.500000000036595] 8211 kex = [1235.20361276079, 2378.31403454691] 8212 delta_omega = [7.08194146569694, 5.4083562844306] 8213 chi2 = [0.0370400968727768, 0.182141732163934] 8214 8215 # Alias the spins. 8216 spin1 = cdp.mol[0].res[0].spin[0] 8217 spin2 = cdp.mol[0].res[1].spin[0] 8218 8219 # The R20 keys. 8220 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8221 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8222 8223 # Printout. 8224 print("\n\nOptimised parameters:\n") 8225 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8226 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8227 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8228 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8229 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8230 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8231 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8232 8233 # Check each spin. 8234 spin_index = 0 8235 for spin, spin_id in spin_loop(return_id=True): 8236 # Printout. 8237 print("\nSpin %s." % spin_id) 8238 8239 # Check the fitted parameters. 8240 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8241 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8242 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8243 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8244 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8245 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8246 8247 # Increment the spin index. 8248 spin_index += 1
8249 8250
8251 - def test_tp02_data_to_tap03(self):
8252 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8253 8254 # Fixed time variable and the models. 8255 ds.fixed = True 8256 ds.models = ['R2eff', 'TAP03'] 8257 8258 # Execute the script. 8259 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8260 8261 # Switch back to the data pipe for the optimisation. 8262 self.interpreter.pipe.switch('TAP03 - relax_disp') 8263 8264 # The equivalent TAP03 parameters. 8265 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8266 pA = [0.775042569092891, 0.500000000229685] 8267 kex = [1235.20852748765, 2379.47085580169] 8268 delta_omega = [7.08176806468445, 5.40708372863538] 8269 chi2 = [0.0371366837083293, 0.182212857256044] 8270 8271 # Alias the spins. 8272 spin1 = cdp.mol[0].res[0].spin[0] 8273 spin2 = cdp.mol[0].res[1].spin[0] 8274 8275 # The R20 keys. 8276 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8277 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8278 8279 # Printout. 8280 print("\n\nOptimised parameters:\n") 8281 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8282 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8283 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8284 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8285 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8286 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8287 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8288 8289 # Switch to the 'MP05' model data pipe, then check for each spin. 8290 self.interpreter.pipe.switch('TAP03 - relax_disp') 8291 spin_index = 0 8292 for spin, spin_id in spin_loop(return_id=True): 8293 # Printout. 8294 print("\nSpin %s." % spin_id) 8295 8296 # Check the fitted parameters. 8297 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8298 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8299 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8300 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8301 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8302 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8303 8304 # Increment the spin index. 8305 spin_index += 1
8306 8307
8308 - def test_tp02_data_to_tp02(self):
8309 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8310 8311 # Fixed time variable. 8312 ds.fixed = True 8313 8314 # Execute the script. 8315 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8316 8317 # The original parameters. 8318 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8319 pA = 0.7654321 8320 kex = 1234.56789 8321 delta_omega = [7.0, 9.0] 8322 8323 # The R20 keys. 8324 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8325 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8326 8327 # Switch to the 'TP02' model data pipe, then check for each spin. 8328 self.interpreter.pipe.switch('TP02 - relax_disp') 8329 spin_index = 0 8330 for spin, spin_id in spin_loop(return_id=True): 8331 # Printout. 8332 print("\nSpin %s." % spin_id) 8333 8334 # Check the fitted parameters. 8335 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8336 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8337 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8338 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8339 8340 # Increment the spin index. 8341 spin_index += 1
8342 8343
8345 """System test of the value.write function to write intensities for an R1rho setup. 8346 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8347 8348 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8349 """ 8350 8351 # Load the state. 8352 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8353 self.interpreter.state.load(statefile, force=True) 8354 8355 # Set filepaths. 8356 int_filepath = ds.tmpdir+sep+'int.out' 8357 8358 # Write out the intensity parameter file. 8359 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8360 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8361 8362 # Test the file exists. 8363 self.assert_(access(int_filepath, F_OK)) 8364 8365 # Open the files for testing. 8366 int_file = open(int_filepath, 'r') 8367 8368 # Loop over the intensity file to test values. 8369 for line in int_file: 8370 # Skip lines starting with #. 8371 if line[0] == "#": 8372 continue 8373 8374 # Split the line 8375 linesplit = line.split() 8376 8377 # Assume values 8378 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8379 self.assertEqual(linesplit[5], "115571.4") 8380 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8381 self.assertEqual(linesplit[5], "68377.52") 8382 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8383 self.assertEqual(linesplit[5], "9141.689") 8384 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8385 self.assertEqual(linesplit[5], "29123.77") 8386 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8387 self.assertEqual(linesplit[5], "58914.94") 8388 8389 # Close files 8390 int_file.close()
8391 8392
8394 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8395 8396 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8397 """ 8398 8399 # Load the state. 8400 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8401 self.interpreter.state.load(statefile, force=True) 8402 8403 # Set filepaths. 8404 theta_filepath = ds.tmpdir+sep+'theta.out' 8405 8406 # Write out the theta parameter file. 8407 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8408 8409 # Test the file exists. 8410 self.assert_(access(theta_filepath, F_OK)) 8411 8412 # Open the files for testing. 8413 theta_file = open(theta_filepath, 'r') 8414 8415 # Loop over the theta file to test values. 8416 for line in theta_file: 8417 # Skip lines starting with #. 8418 if line[0] == "#": 8419 continue 8420 # Print lines, not including newline character. 8421 print(line[:-1]) 8422 8423 # Split the line 8424 linesplit = line.split() 8425 8426 # Assume values 8427 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8428 self.assertNotEqual(linesplit[5], "None") 8429 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8430 self.assertNotEqual(linesplit[5], "None") 8431 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8432 self.assertNotEqual(linesplit[5], "None") 8433 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8434 self.assertNotEqual(linesplit[5], "None") 8435 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8436 self.assertNotEqual(linesplit[5], "None") 8437 8438 # Close files 8439 theta_file.close()
8440 8441
8443 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8444 8445 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8446 """ 8447 8448 # Load the state. 8449 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8450 self.interpreter.state.load(statefile, force=True) 8451 8452 # Set filepaths. 8453 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8454 8455 # Write out the w_eff parameter file. 8456 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8457 8458 # Test the file exists. 8459 self.assert_(access(w_eff_filepath, F_OK)) 8460 8461 # Open the files for testing. 8462 w_eff_file = open(w_eff_filepath, 'r') 8463 8464 # Loop over the w_eff file to test values. 8465 for line in w_eff_file: 8466 # Skip lines starting with #. 8467 if line[0] == "#": 8468 continue 8469 # Print lines, not including newline character. 8470 print(line[:-1]) 8471 8472 # Split the line 8473 linesplit = line.split() 8474 8475 # Assume values 8476 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8477 self.assertNotEqual(linesplit[5], "None") 8478 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8479 self.assertNotEqual(linesplit[5], "None") 8480 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8481 self.assertNotEqual(linesplit[5], "None") 8482 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8483 self.assertNotEqual(linesplit[5], "None") 8484 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8485 self.assertNotEqual(linesplit[5], "None") 8486 8487 # Close files 8488 w_eff_file.close()
8489 8490
8492 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8493 8494 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8495 """ 8496 8497 # Load the state. 8498 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8499 self.interpreter.state.load(statefile, force=True) 8500 8501 # Set pipe name, bundle and type. 8502 pipe_name = 'base pipe' 8503 pipe_bundle = 'relax_disp' 8504 pipe_type = 'relax_disp' 8505 8506 # The path to the data files. 8507 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8508 8509 # Deselect all spins 8510 self.interpreter.deselect.all() 8511 8512 # Specify spins to be selected. 8513 select_spin_ids = [ 8514 ":13@N", 8515 ":15@N", 8516 ":16@N", 8517 ":25@N", 8518 ":26@N", 8519 ":28@N", 8520 ":39@N", 8521 ":40@N", 8522 ":41@N", 8523 ":43@N", 8524 ":44@N", 8525 ":45@N", 8526 ":49@N", 8527 ":52@N", 8528 ":53@N"] 8529 8530 # Reverse the selection for the spins. 8531 for curspin in select_spin_ids: 8532 print("Selecting spin %s"%curspin) 8533 self.interpreter.deselect.reverse(spin_id=curspin) 8534 8535 # Read the R1 data 8536 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 8537 8538 # The dispersion models. 8539 MODELS = ['R2eff'] 8540 8541 # The grid search size (the number of increments per dimension). 8542 GRID_INC = 4 8543 8544 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8545 MC_NUM = 3 8546 8547 # Model selection technique. 8548 MODSEL = 'AIC' 8549 8550 # Execute the auto-analysis (fast). 8551 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8552 OPT_FUNC_TOL = 1e-1 8553 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8554 OPT_MAX_ITERATIONS = 1000 8555 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8556 8557 # Run the analysis. 8558 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 8559 8560 ## Check for file creation 8561 # Set filepaths. 8562 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8563 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8564 8565 # Test the files exists. 8566 self.assert_(access(theta_filepath, F_OK)) 8567 self.assert_(access(w_eff_filepath, F_OK)) 8568 8569 # Open the files for testing. 8570 theta_file = open(theta_filepath, 'r') 8571 theta_result = [ 8572 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8573 "#\n", 8574 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8575 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8576 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8577 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8578 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8579 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8580 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8581 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8582 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 8583 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8584 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 8585 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 8586 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8587 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8588 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8589 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8590 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8591 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 8592 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 8593 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8594 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 8595 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8596 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8597 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8598 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8599 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8600 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8601 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8602 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8603 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8604 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 8605 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 8606 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 8607 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8608 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 8609 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 8610 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 8611 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8612 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8613 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 8614 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8615 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8616 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 8617 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 8618 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8619 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8620 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8621 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8622 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8623 ] 8624 # Check the created theta file. 8625 lines = theta_file.readlines() 8626 for i in range(len(lines)): 8627 # Test lines starting with # 8628 if theta_result[i][0] == "#": 8629 self.assertEqual(theta_result[i], lines[i]) 8630 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8631 if theta_result[i] == lines[i]: 8632 self.assertEqual(theta_result[i], lines[i]) 8633 # If the line is not equal each other, make a slower comparison of values. 8634 else: 8635 # Print lines if they don't match. To help find differences. 8636 print(theta_result[i]) 8637 print(lines[i]) 8638 8639 # First test first 62 characters containing spin information 8640 self.assertEqual(theta_result[i][:62], lines[i][:62]) 8641 8642 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8643 theta_result_s = theta_result[i][62:].split()[::2] 8644 print(theta_result_s ) 8645 lines_s = lines[i][62:].split()[::2] 8646 print(lines_s) 8647 # Loop over the value elements 8648 for j in range(len(lines_s)): 8649 print(theta_result_s[j], lines_s[j]) 8650 # Assume a precision to digits. 8651 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 8652 8653 # Close file 8654 theta_file.close() 8655 8656 w_eff_file = open(w_eff_filepath, 'r') 8657 w_eff_result = [ 8658 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 8659 "#\n", 8660 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8661 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8662 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8663 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8664 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8665 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8666 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8667 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8668 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 8669 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8670 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 8671 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 8672 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8673 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8674 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8675 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8676 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8677 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 8678 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 8679 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8680 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 8681 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8682 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8683 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8684 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8685 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8686 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8687 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8688 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8689 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8690 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 8691 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 8692 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 8693 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8694 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 8695 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 8696 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 8697 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8698 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8699 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 8700 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8701 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8702 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 8703 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 8704 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8705 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8706 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8707 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8708 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8709 ] 8710 # Check the created w_eff file. 8711 lines = w_eff_file.readlines() 8712 for i in range(len(lines)): 8713 # Test lines starting with # 8714 if w_eff_result[i][0] == "#": 8715 self.assertEqual(w_eff_result[i], lines[i]) 8716 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8717 if w_eff_result[i] == lines[i]: 8718 self.assertEqual(w_eff_result[i], lines[i]) 8719 # If the line is not equal each other, make a slower comparison of values. 8720 else: 8721 # Print lines if they don't match. To help find differences. 8722 print(w_eff_result[i]) 8723 print(lines[i]) 8724 8725 # First test first 62 characters containing spin information 8726 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 8727 8728 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8729 w_eff_result_s = w_eff_result[i][62:].split()[::2] 8730 print(w_eff_result_s ) 8731 lines_s = lines[i][62:].split()[::2] 8732 print(lines_s) 8733 # Loop over the value elements 8734 for j in range(len(lines_s)): 8735 print(w_eff_result_s[j], lines_s[j]) 8736 # Assume a precision to digits. 8737 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 8738 8739 # Close file 8740 w_eff_file.close()
8741 8742
8744 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 8745 8746 This follows Task 7822. 8747 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 8748 8749 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 8750 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 8751 """ 8752 8753 # Load the data. 8754 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 8755 8756 # Set pipe name, bundle and type. 8757 pipe_name = 'base pipe' 8758 pipe_bundle = 'relax_disp' 8759 pipe_type = 'relax_disp' 8760 8761 # Create the data pipe. 8762 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 8763 8764 file = data_path + '1_setup_r1rho_GUI.py' 8765 self.interpreter.script(file=file, dir=None) 8766 8767 # Deselect all spins. 8768 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 8769 8770 # Select one spin. 8771 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 8772 8773 # Set the model. 8774 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8775 8776 # Check if intensity errors have already been calculated. 8777 check_intensity_errors() 8778 8779 # Do a grid search. 8780 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 8781 8782 # Set algorithm. 8783 min_algor = 'Newton' 8784 constraints = True 8785 if constraints: 8786 min_options = ('%s'%(min_algor),) 8787 #min_algor = 'Log barrier' 8788 min_algor = 'Method of Multipliers' 8789 scaling_matrix = assemble_scaling_matrix(scaling=True) 8790 8791 # Collect spins 8792 all_spin_ids = [] 8793 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8794 all_spin_ids.append(spin_id) 8795 8796 spins = spin_ids_to_containers(all_spin_ids[:1]) 8797 8798 # Get constraints 8799 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 8800 else: 8801 min_options = () 8802 A, b = None, None 8803 min_options = () 8804 sim_boot = 200 8805 scaling_list = [1.0, 1.0] 8806 8807 # Minimise. 8808 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 8809 8810 # Loop over old err attributes. 8811 err_attr_list = ['r2eff_err', 'i0_err'] 8812 8813 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8814 # Loop over old err attributes. 8815 for err_attr in err_attr_list: 8816 if hasattr(cur_spin, err_attr): 8817 delattr(cur_spin, err_attr) 8818 8819 # Collect the estimation data from boot. 8820 my_dic = {} 8821 param_key_list = [] 8822 est_keys = [] 8823 est_key = '-2' 8824 est_keys.append(est_key) 8825 spin_id_list = [] 8826 8827 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8828 # Add key to dic. 8829 my_dic[spin_id] = {} 8830 8831 # Add key for estimate. 8832 my_dic[spin_id][est_key] = {} 8833 8834 # Add spin key to list. 8835 spin_id_list.append(spin_id) 8836 8837 # Generate spin string. 8838 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8839 8840 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8841 # Generate the param_key. 8842 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8843 8844 # Append key. 8845 param_key_list.append(param_key) 8846 8847 # Add key to dic. 8848 my_dic[spin_id][est_key][param_key] = {} 8849 8850 values = [] 8851 errors = [] 8852 times = [] 8853 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 8854 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 8855 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 8856 times.append(time) 8857 8858 # Convert to numpy array. 8859 values = asarray(values) 8860 errors = asarray(errors) 8861 times = asarray(times) 8862 8863 r2eff = getattr(cur_spin, 'r2eff')[param_key] 8864 i0 = getattr(cur_spin, 'i0')[param_key] 8865 8866 R_m_sim_l = [] 8867 I0_m_sim_l = [] 8868 for j in range(sim_boot): 8869 if j in range(0, 100000, 100): 8870 print("Simulation %i"%j) 8871 # Start minimisation. 8872 8873 # Produce errors 8874 I_err = [] 8875 for j, error in enumerate(errors): 8876 I_error = gauss(values[j], error) 8877 I_err.append(I_error) 8878 # Convert to numpy array. 8879 I_err = asarray(I_err) 8880 8881 x0 = [r2eff, i0] 8882 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 8883 8884 # Ref input. 8885 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 8886 # l=l, u=u, c=c, dc=dc, d2c=d2c 8887 # l: Lower bound constraint vector (l <= x <= u). 8888 # u: Upper bound constraint vector (l <= x <= u). 8889 # c: User supplied constraint function. 8890 # dc: User supplied constraint gradient function. 8891 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 8892 8893 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 8894 R_m_sim_l.append(R_m_sim_j) 8895 I0_m_sim_l.append(I0_m_sim_j) 8896 8897 # Get stats on distribution. 8898 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 8899 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 8900 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 8901 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 8902 8903 # Estimate R2eff errors. 8904 self.interpreter.relax_disp.r2eff_err_estimate() 8905 8906 est_key = '-1' 8907 est_keys.append(est_key) 8908 8909 # Collect data. 8910 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8911 # Add key for estimate. 8912 my_dic[spin_id][est_key] = {} 8913 8914 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8915 # Generate the param_key. 8916 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8917 8918 # Add key to dic. 8919 my_dic[spin_id][est_key][param_key] = {} 8920 8921 # Get the value. 8922 # Loop over err attributes. 8923 for err_attr in err_attr_list: 8924 if hasattr(cur_spin, err_attr): 8925 get_err_attr = getattr(cur_spin, err_attr)[param_key] 8926 else: 8927 get_err_attr = 0.0 8928 8929 # Save to dic. 8930 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 8931 8932 8933 # Make Carlo Simulations number 8934 mc_number_list = list(range(0, 1000, 250)) 8935 8936 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 8937 8938 # Loop over the Monte Carlo simulations: 8939 for number in mc_number_list: 8940 # First delete old simulations. 8941 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8942 # Loop over old err attributes. 8943 for err_attr in err_attr_list: 8944 if hasattr(cur_spin, err_attr): 8945 delattr(cur_spin, err_attr) 8946 8947 # Loop over the simulated attributes. 8948 for sim_attr in sim_attr_list: 8949 if hasattr(cur_spin, sim_attr): 8950 delattr(cur_spin, sim_attr) 8951 8952 self.interpreter.monte_carlo.setup(number=number) 8953 self.interpreter.monte_carlo.create_data() 8954 self.interpreter.monte_carlo.initial_values() 8955 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 8956 self.interpreter.eliminate() 8957 self.interpreter.monte_carlo.error_analysis() 8958 8959 est_key = '%i'%number 8960 est_keys.append(est_key) 8961 8962 # Collect data. 8963 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8964 # Add key for estimate. 8965 my_dic[spin_id][est_key] = {} 8966 8967 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8968 # Generate the param_key. 8969 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8970 8971 # Add key to dic. 8972 my_dic[spin_id][est_key][param_key] = {} 8973 8974 # Get the value. 8975 # Loop over err attributes. 8976 for err_attr in err_attr_list: 8977 if hasattr(cur_spin, err_attr): 8978 get_err_attr = getattr(cur_spin, err_attr)[param_key] 8979 else: 8980 get_err_attr = 0.0 8981 8982 # Save to dic. 8983 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 8984 8985 # Set what to extract. 8986 err_attr = err_attr_list[0] 8987 8988 # Define list with text. 8989 text_list = [] 8990 8991 # Now loop through the data. 8992 for spin_id in spin_id_list: 8993 for est_key in est_keys: 8994 # Define list to pickup data. 8995 r2eff_err_list = [] 8996 8997 for param_key in param_key_list: 8998 # Get the value. 8999 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9000 9001 # Add to list. 9002 r2eff_err_list.append(r2eff_err) 9003 9004 # Sum the list 9005 sum_array = sum(array(r2eff_err_list)) 9006 9007 # Join floats to string. 9008 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9009 9010 # Define print string. 9011 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9012 text_list.append(text) 9013 9014 9015 # Now print. 9016 filepath = NamedTemporaryFile(delete=False).name 9017 # Open the files for testing. 9018 w_file = open(filepath, 'w') 9019 9020 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9021 9022 for text in text_list: 9023 # Print. 9024 print(text) 9025 9026 # Write to file. 9027 w_file.write(text+"\n") 9028 9029 # Close files 9030 w_file.close() 9031 9032 print("Filepath is: %s"%filepath) 9033 print("Start 'gnuplot' and write:") 9034 print("set term dumb") 9035 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9036 9037
9038 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9039 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9040 9041 # Check the kex value of residue 52 9042 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9043 9044 # Print results for each model. 9045 print("\n\n################") 9046 print("Printing results") 9047 print("################\n") 9048 for model in models: 9049 # Skip R2eff model. 9050 if model == MODEL_R2EFF: 9051 continue 9052 9053 # Switch to pipe. 9054 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9055 print("\nModel: %s" % (model)) 9056 9057 # Loop over the spins. 9058 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9059 # Generate spin string. 9060 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9061 9062 # Loop over the parameters. 9063 print("Optimised parameters for spin: %s" % (spin_string)) 9064 for param in cur_spin.params + ['chi2']: 9065 # Get the value. 9066 if param in ['r1', 'r2']: 9067 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9068 # Generate the R20 key. 9069 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9070 9071 # Get the value. 9072 value = getattr(cur_spin, param)[r20_key] 9073 9074 # Print value. 9075 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9076 9077 # Compare values. 9078 if spin_id == ':52@N': 9079 if param == 'r1': 9080 if model == MODEL_NOREX: 9081 if r2eff_estimate == 'direct': 9082 self.assertAlmostEqual(value, 1.46138805) 9083 elif r2eff_estimate == 'MC2000': 9084 self.assertAlmostEqual(value, 1.46328102) 9085 elif r2eff_estimate == 'chi2_pyt': 9086 self.assertAlmostEqual(value, 1.43820629) 9087 elif model == MODEL_DPL94: 9088 if r2eff_estimate == 'direct': 9089 self.assertAlmostEqual(value, 1.44845742) 9090 elif r2eff_estimate == 'MC2000': 9091 self.assertAlmostEqual(value, 1.45019848) 9092 elif r2eff_estimate == 'chi2_pyt': 9093 self.assertAlmostEqual(value, 1.44666512) 9094 elif model == MODEL_TP02: 9095 if r2eff_estimate == 'direct': 9096 self.assertAlmostEqual(value, 1.54354392) 9097 elif r2eff_estimate == 'MC2000': 9098 self.assertAlmostEqual(value, 1.54352369) 9099 elif r2eff_estimate == 'chi2_pyt': 9100 self.assertAlmostEqual(value, 1.55964020) 9101 elif model == MODEL_TAP03: 9102 if r2eff_estimate == 'direct': 9103 self.assertAlmostEqual(value, 1.54356410) 9104 elif r2eff_estimate == 'MC2000': 9105 self.assertAlmostEqual(value, 1.54354367) 9106 elif r2eff_estimate == 'chi2_pyt': 9107 self.assertAlmostEqual(value, 1.55967157) 9108 elif model == MODEL_MP05: 9109 if r2eff_estimate == 'direct': 9110 self.assertAlmostEqual(value, 1.54356416) 9111 elif r2eff_estimate == 'MC2000': 9112 self.assertAlmostEqual(value, 1.54354372) 9113 elif r2eff_estimate == 'chi2_pyt': 9114 self.assertAlmostEqual(value, 1.55967163) 9115 elif model == MODEL_NS_R1RHO_2SITE: 9116 if r2eff_estimate == 'direct': 9117 self.assertAlmostEqual(value, 1.41359221, 5) 9118 elif r2eff_estimate == 'MC2000': 9119 self.assertAlmostEqual(value, 1.41321968, 5) 9120 elif r2eff_estimate == 'chi2_pyt': 9121 self.assertAlmostEqual(value, 1.36303129, 5) 9122 9123 elif param == 'r2': 9124 if model == MODEL_NOREX: 9125 if r2eff_estimate == 'direct': 9126 self.assertAlmostEqual(value, 11.48392439) 9127 elif r2eff_estimate == 'MC2000': 9128 self.assertAlmostEqual(value, 11.48040934) 9129 elif r2eff_estimate == 'chi2_pyt': 9130 self.assertAlmostEqual(value, 11.47224488) 9131 elif model == MODEL_DPL94: 9132 if r2eff_estimate == 'direct': 9133 self.assertAlmostEqual(value, 10.15688372, 6) 9134 elif r2eff_estimate == 'MC2000': 9135 self.assertAlmostEqual(value, 10.16304887, 6) 9136 elif r2eff_estimate == 'chi2_pyt': 9137 self.assertAlmostEqual(value, 9.20037797, 6) 9138 elif model == MODEL_TP02: 9139 if r2eff_estimate == 'direct': 9140 self.assertAlmostEqual(value, 9.72654896, 6) 9141 elif r2eff_estimate == 'MC2000': 9142 self.assertAlmostEqual(value, 9.72772726, 6) 9143 elif r2eff_estimate == 'chi2_pyt': 9144 self.assertAlmostEqual(value, 9.53948340, 6) 9145 elif model == MODEL_TAP03: 9146 if r2eff_estimate == 'direct': 9147 self.assertAlmostEqual(value, 9.72641887, 6) 9148 elif r2eff_estimate == 'MC2000': 9149 self.assertAlmostEqual(value, 9.72759374, 6) 9150 elif r2eff_estimate == 'chi2_pyt': 9151 self.assertAlmostEqual(value, 9.53926913, 6) 9152 elif model == MODEL_MP05: 9153 if r2eff_estimate == 'direct': 9154 self.assertAlmostEqual(value, 9.72641723, 6) 9155 elif r2eff_estimate == 'MC2000': 9156 self.assertAlmostEqual(value, 9.72759220, 6) 9157 elif r2eff_estimate == 'chi2_pyt': 9158 self.assertAlmostEqual(value, 9.53926778, 6) 9159 elif model == MODEL_NS_R1RHO_2SITE: 9160 if r2eff_estimate == 'direct': 9161 self.assertAlmostEqual(value, 9.34531535, 5) 9162 elif r2eff_estimate == 'MC2000': 9163 self.assertAlmostEqual(value, 9.34602793, 5) 9164 elif r2eff_estimate == 'chi2_pyt': 9165 self.assertAlmostEqual(value, 9.17631409, 5) 9166 9167 # For all other parameters. 9168 else: 9169 # Get the value. 9170 value = getattr(cur_spin, param) 9171 9172 # Print value. 9173 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9174 9175 # Compare values. 9176 if spin_id == ':52@N': 9177 if param == 'phi_ex': 9178 if model == MODEL_DPL94: 9179 if r2eff_estimate == 'direct': 9180 self.assertAlmostEqual(value, 0.07599563) 9181 elif r2eff_estimate == 'MC2000': 9182 self.assertAlmostEqual(value, 0.07561937) 9183 elif r2eff_estimate == 'chi2_pyt': 9184 self.assertAlmostEqual(value, 0.12946061) 9185 9186 elif param == 'pA': 9187 if model == MODEL_TP02: 9188 if r2eff_estimate == 'direct': 9189 self.assertAlmostEqual(value, 0.88827040) 9190 elif r2eff_estimate == 'MC2000': 9191 self.assertAlmostEqual(value, 0.88807487) 9192 elif r2eff_estimate == 'chi2_pyt': 9193 self.assertAlmostEqual(value, 0.87746233) 9194 elif model == MODEL_TAP03: 9195 if r2eff_estimate == 'direct': 9196 self.assertAlmostEqual(value, 0.88828922) 9197 elif r2eff_estimate == 'MC2000': 9198 self.assertAlmostEqual(value, 0.88809318) 9199 elif r2eff_estimate == 'chi2_pyt': 9200 self.assertAlmostEqual(value, 0.87747558) 9201 elif model == MODEL_MP05: 9202 if r2eff_estimate == 'direct': 9203 self.assertAlmostEqual(value, 0.88828924, 6) 9204 elif r2eff_estimate == 'MC2000': 9205 self.assertAlmostEqual(value, 0.88809321) 9206 elif r2eff_estimate == 'chi2_pyt': 9207 self.assertAlmostEqual(value, 0.87747562) 9208 elif model == MODEL_NS_R1RHO_2SITE: 9209 if r2eff_estimate == 'direct': 9210 self.assertAlmostEqual(value, 0.94504369, 6) 9211 elif r2eff_estimate == 'MC2000': 9212 self.assertAlmostEqual(value, 0.94496541, 6) 9213 elif r2eff_estimate == 'chi2_pyt': 9214 self.assertAlmostEqual(value, 0.92084707, 6) 9215 9216 elif param == 'dw': 9217 if model == MODEL_TP02: 9218 if r2eff_estimate == 'direct': 9219 self.assertAlmostEqual(value, 1.08875840, 6) 9220 elif r2eff_estimate == 'MC2000': 9221 self.assertAlmostEqual(value, 1.08765638, 6) 9222 elif r2eff_estimate == 'chi2_pyt': 9223 self.assertAlmostEqual(value, 1.09753230, 6) 9224 elif model == MODEL_TAP03: 9225 if r2eff_estimate == 'direct': 9226 self.assertAlmostEqual(value, 1.08837238, 6) 9227 elif r2eff_estimate == 'MC2000': 9228 self.assertAlmostEqual(value, 1.08726698, 6) 9229 elif r2eff_estimate == 'chi2_pyt': 9230 self.assertAlmostEqual(value, 1.09708821, 6) 9231 elif model == MODEL_MP05: 9232 if r2eff_estimate == 'direct': 9233 self.assertAlmostEqual(value, 1.08837241, 6) 9234 elif r2eff_estimate == 'MC2000': 9235 self.assertAlmostEqual(value, 1.08726706, 6) 9236 elif r2eff_estimate == 'chi2_pyt': 9237 self.assertAlmostEqual(value, 1.09708832, 6) 9238 elif model == MODEL_NS_R1RHO_2SITE: 9239 if r2eff_estimate == 'direct': 9240 self.assertAlmostEqual(value, 1.56001812, 5) 9241 elif r2eff_estimate == 'MC2000': 9242 self.assertAlmostEqual(value, 1.55833321, 5) 9243 elif r2eff_estimate == 'chi2_pyt': 9244 self.assertAlmostEqual(value, 1.36406712, 5) 9245 9246 elif param == 'kex': 9247 if model == MODEL_DPL94: 9248 if r2eff_estimate == 'direct': 9249 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9250 elif r2eff_estimate == 'MC2000': 9251 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9252 elif r2eff_estimate == 'chi2_pyt': 9253 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9254 elif model == MODEL_TP02: 9255 if r2eff_estimate == 'direct': 9256 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9257 elif r2eff_estimate == 'MC2000': 9258 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9259 elif r2eff_estimate == 'chi2_pyt': 9260 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9261 elif model == MODEL_TAP03: 9262 if r2eff_estimate == 'direct': 9263 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9264 elif r2eff_estimate == 'MC2000': 9265 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9266 elif r2eff_estimate == 'chi2_pyt': 9267 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9268 elif model == MODEL_MP05: 9269 if r2eff_estimate == 'direct': 9270 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9271 elif r2eff_estimate == 'MC2000': 9272 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9273 elif r2eff_estimate == 'chi2_pyt': 9274 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9275 elif model == MODEL_NS_R1RHO_2SITE: 9276 if r2eff_estimate == 'direct': 9277 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9278 elif r2eff_estimate == 'MC2000': 9279 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9280 elif r2eff_estimate == 'chi2_pyt': 9281 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9282 9283 elif param == 'chi2': 9284 if model == MODEL_NOREX: 9285 if r2eff_estimate == 'direct': 9286 self.assertAlmostEqual(value, 848.42016907, 5) 9287 elif r2eff_estimate == 'MC2000': 9288 self.assertAlmostEqual(value, 3363.95829122, 5) 9289 elif r2eff_estimate == 'chi2_pyt': 9290 self.assertAlmostEqual(value, 5976.49946726, 5) 9291 elif model == MODEL_DPL94: 9292 if r2eff_estimate == 'direct': 9293 self.assertAlmostEqual(value, 179.47041241) 9294 elif r2eff_estimate == 'MC2000': 9295 self.assertAlmostEqual(value, 710.24767560) 9296 elif r2eff_estimate == 'chi2_pyt': 9297 self.assertAlmostEqual(value, 612.72616697, 5) 9298 elif model == MODEL_TP02: 9299 if r2eff_estimate == 'direct': 9300 self.assertAlmostEqual(value, 29.33882530, 6) 9301 elif r2eff_estimate == 'MC2000': 9302 self.assertAlmostEqual(value, 114.47142772, 6) 9303 elif r2eff_estimate == 'chi2_pyt': 9304 self.assertAlmostEqual(value, 250.50838162, 5) 9305 elif model == MODEL_TAP03: 9306 if r2eff_estimate == 'direct': 9307 self.assertAlmostEqual(value, 29.29050673, 6) 9308 elif r2eff_estimate == 'MC2000': 9309 self.assertAlmostEqual(value, 114.27987534) 9310 elif r2eff_estimate == 'chi2_pyt': 9311 self.assertAlmostEqual(value, 250.04050719, 5) 9312 elif model == MODEL_MP05: 9313 if r2eff_estimate == 'direct': 9314 self.assertAlmostEqual(value, 29.29054301, 6) 9315 elif r2eff_estimate == 'MC2000': 9316 self.assertAlmostEqual(value, 114.28002272) 9317 elif r2eff_estimate == 'chi2_pyt': 9318 self.assertAlmostEqual(value, 250.04077478, 5) 9319 elif model == MODEL_NS_R1RHO_2SITE: 9320 if r2eff_estimate == 'direct': 9321 self.assertAlmostEqual(value, 34.44010543, 6) 9322 elif r2eff_estimate == 'MC2000': 9323 self.assertAlmostEqual(value, 134.14368365) 9324 elif r2eff_estimate == 'chi2_pyt': 9325 self.assertAlmostEqual(value, 278.55121388, 5) 9326 9327 9328 # Print the final pipe. 9329 model = 'final' 9330 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9331 print("\nFinal pipe") 9332 9333 # Loop over the spins. 9334 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9335 # Generate spin string. 9336 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9337 9338 # Loop over the parameters. 9339 print("Optimised model for spin: %s" % (spin_string)) 9340 param = 'model' 9341 9342 # Get the value. 9343 value = getattr(cur_spin, param) 9344 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9345 9346 9347 ### Now check some of the written out files. 9348 file_names = ['r1rho_prime', 'r1'] 9349 9350 for file_name_i in file_names: 9351 9352 # Make the file name. 9353 file_name = "%s.out" % file_name_i 9354 9355 # Get the file path. 9356 file_path = get_file_path(file_name, result_dir_name + sep + model) 9357 9358 # Test the file exists. 9359 print("Testing file access to: %s"%file_path) 9360 self.assert_(access(file_path, F_OK)) 9361 9362 # Now open, and compare content, line by line. 9363 file_prod = open(file_path) 9364 lines_prod = file_prod.readlines() 9365 file_prod.close() 9366 9367 # Loop over the lines. 9368 for i, line in enumerate(lines_prod): 9369 # Make the string test 9370 line_split = line.split() 9371 9372 # Continue for comment lines. 9373 if line_split[0] == "#": 9374 print(line), 9375 continue 9376 9377 # Assign the split of the line. 9378 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9379 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9380 9381 if res_num == '52': 9382 # Assert that the value is not None. 9383 self.assertNotEqual(val, 'None')
9384